Annotation of loncom/homework/grades.pm, revision 1.556
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.556 ! weissno 4: # $Id: grades.pm,v 1.556 2009/03/09 02:14:50 weissno 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);
1.555 raeburn 271: my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
272: if (ref($foils) eq 'ARRAY') {
273: foreach my $foil (@{$foils}) {
274: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
275: return $foil;
276: }
1.434 albertel 277: }
278: }
279: }
1.554 raeburn 280:
281: sub scantron_partids_tograde {
282: my ($resource,$cid,$uname,$udom) = @_;
283: my (%analysis,@parts);
284: if (ref($resource)) {
285: my $symb = $resource->symb();
286: my $analyze = &get_analyze($symb,$uname,$udom);
287: if (ref($analyze) eq 'HASH') {
288: %analysis = %{$analyze};
289: }
290: if (ref($analysis{'parts'}) eq 'ARRAY') {
291: foreach my $part (@{$analysis{'parts'}}) {
292: my ($id,$respid) = split(/\./,$part);
293: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
294: push(@parts,$part);
295: }
296: }
297: }
298: }
299: return (\%analysis,\@parts);
300: }
301:
1.148 albertel 302: }
1.434 albertel 303:
1.118 ng 304: #--- Clean response type for display
1.335 albertel 305: #--- Currently filters option/rank/radiobutton/match/essay/Task
306: # response types only.
1.118 ng 307: sub cleanRecord {
1.336 albertel 308: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
309: $uname,$udom) = @_;
1.398 albertel 310: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 311: if ($response =~ /^(option|rank)$/) {
312: my %answer=&Apache::lonnet::str2hash($answer);
313: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
314: my ($toprow,$bottomrow);
315: foreach my $foil (@$order) {
316: if ($grading{$foil} == 1) {
317: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
318: } else {
319: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
320: }
1.398 albertel 321: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 322: }
323: return '<blockquote><table border="1">'.
1.466 albertel 324: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
325: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 326: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
327: } elsif ($response eq 'match') {
328: my %answer=&Apache::lonnet::str2hash($answer);
329: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
330: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
331: my ($toprow,$middlerow,$bottomrow);
332: foreach my $foil (@$order) {
333: my $item=shift(@items);
334: if ($grading{$foil} == 1) {
335: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 336: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 337: } else {
338: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 339: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 340: }
1.398 albertel 341: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 342: }
1.126 ng 343: return '<blockquote><table border="1">'.
1.466 albertel 344: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
345: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 346: $middlerow.'</tr>'.
1.466 albertel 347: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 348: $bottomrow.'</tr>'.'</table></blockquote>';
349: } elsif ($response eq 'radiobutton') {
350: my %answer=&Apache::lonnet::str2hash($answer);
351: my ($toprow,$bottomrow);
1.434 albertel 352: my $correct =
353: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
354: foreach my $foil (@$order) {
1.148 albertel 355: if (exists($answer{$foil})) {
1.434 albertel 356: if ($foil eq $correct) {
1.466 albertel 357: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 358: } else {
1.466 albertel 359: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 360: }
361: } else {
1.466 albertel 362: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 363: }
1.398 albertel 364: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 365: }
366: return '<blockquote><table border="1">'.
1.466 albertel 367: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
368: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 369: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
370: } elsif ($response eq 'essay') {
1.257 albertel 371: if (! exists ($env{'form.'.$symb})) {
1.122 ng 372: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 373: $env{'course.'.$env{'request.course.id'}.'.domain'},
374: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 375:
1.257 albertel 376: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
377: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
378: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
379: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
380: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
381: $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 382: }
1.166 albertel 383: $answer =~ s-\n-<br />-g;
384: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 385: } elsif ( $response eq 'organic') {
386: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
387: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
388: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
389: return $result;
1.335 albertel 390: } elsif ( $response eq 'Task') {
391: if ( $answer eq 'SUBMITTED') {
392: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 393: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 394: return $result;
395: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
396: my @matches = grep(/^\Q$version\E.*?\.instance$/,
397: keys(%{$record}));
398: return join('<br />',($version,@matches));
399:
400:
401: } else {
402: my $result =
403: '<p>'
404: .&mt('Overall result: [_1]',
405: $record->{$version."resource.$respid.$partid.status"})
406: .'</p>';
407:
408: $result .= '<ul>';
409: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
410: keys(%{$record}));
411: foreach my $grade (sort(@grade)) {
412: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
413: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
414: $dim, $record->{$grade}).
415: '</li>';
416: }
417: $result.='</ul>';
418: return $result;
419: }
1.440 albertel 420: } elsif ( $response =~ m/(?:numerical|formula)/) {
421: $answer =
422: &Apache::loncommon::format_previous_attempt_value('submission',
423: $answer);
1.122 ng 424: }
1.118 ng 425: return $answer;
426: }
427:
428: #-- A couple of common js functions
429: sub commonJSfunctions {
430: my $request = shift;
431: $request->print(<<COMMONJSFUNCTIONS);
432: <script type="text/javascript" language="javascript">
433: function radioSelection(radioButton) {
434: var selection=null;
435: if (radioButton.length > 1) {
436: for (var i=0; i<radioButton.length; i++) {
437: if (radioButton[i].checked) {
438: return radioButton[i].value;
439: }
440: }
441: } else {
442: if (radioButton.checked) return radioButton.value;
443: }
444: return selection;
445: }
446:
447: function pullDownSelection(selectOne) {
448: var selection="";
449: if (selectOne.length > 1) {
450: for (var i=0; i<selectOne.length; i++) {
451: if (selectOne[i].selected) {
452: return selectOne[i].value;
453: }
454: }
455: } else {
1.138 albertel 456: // only one value it must be the selected one
457: return selectOne.value;
1.118 ng 458: }
459: }
460: </script>
461: COMMONJSFUNCTIONS
462: }
463:
1.44 ng 464: #--- Dumps the class list with usernames,list of sections,
465: #--- section, ids and fullnames for each user.
466: sub getclasslist {
1.449 banghart 467: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 468: my @getsec;
1.450 banghart 469: my @getgroup;
1.442 banghart 470: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 471: if (!ref($getsec)) {
472: if ($getsec ne '' && $getsec ne 'all') {
473: @getsec=($getsec);
474: }
475: } else {
476: @getsec=@{$getsec};
477: }
478: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 479: if (!ref($getgroup)) {
480: if ($getgroup ne '' && $getgroup ne 'all') {
481: @getgroup=($getgroup);
482: }
483: } else {
484: @getgroup=@{$getgroup};
485: }
486: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 487:
1.449 banghart 488: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 489: # Bail out if we were unable to get the classlist
1.56 matthew 490: return if (! defined($classlist));
1.449 banghart 491: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 492: #
493: my %sections;
494: my %fullnames;
1.205 matthew 495: foreach my $student (keys(%$classlist)) {
496: my $end =
497: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
498: my $start =
499: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
500: my $id =
501: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
502: my $section =
503: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
504: my $fullname =
505: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
506: my $status =
507: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 508: my $group =
509: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 510: # filter students according to status selected
1.442 banghart 511: if ($filterlist && (!($stu_status =~ /Any/))) {
512: if (!($stu_status =~ $status)) {
1.450 banghart 513: delete($classlist->{$student});
1.76 ng 514: next;
515: }
516: }
1.450 banghart 517: # filter students according to groups selected
1.453 banghart 518: my @stu_groups = split(/,/,$group);
1.450 banghart 519: if (@getgroup) {
520: my $exclude = 1;
1.454 banghart 521: foreach my $grp (@getgroup) {
522: foreach my $stu_group (@stu_groups) {
1.453 banghart 523: if ($stu_group eq $grp) {
524: $exclude = 0;
525: }
1.450 banghart 526: }
1.453 banghart 527: if (($grp eq 'none') && !$group) {
528: $exclude = 0;
529: }
1.450 banghart 530: }
531: if ($exclude) {
532: delete($classlist->{$student});
533: }
534: }
1.205 matthew 535: $section = ($section ne '' ? $section : 'none');
1.106 albertel 536: if (&canview($section)) {
1.291 albertel 537: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 538: $sections{$section}++;
1.450 banghart 539: if ($classlist->{$student}) {
540: $fullnames{$student}=$fullname;
541: }
1.103 albertel 542: } else {
1.205 matthew 543: delete($classlist->{$student});
1.103 albertel 544: }
545: } else {
1.205 matthew 546: delete($classlist->{$student});
1.103 albertel 547: }
1.44 ng 548: }
549: my %seen = ();
1.56 matthew 550: my @sections = sort(keys(%sections));
551: return ($classlist,\@sections,\%fullnames);
1.44 ng 552: }
553:
1.103 albertel 554: sub canmodify {
555: my ($sec)=@_;
556: if ($perm{'mgr'}) {
557: if (!defined($perm{'mgr_section'})) {
558: # can modify whole class
559: return 1;
560: } else {
561: if ($sec eq $perm{'mgr_section'}) {
562: #can modify the requested section
563: return 1;
564: } else {
565: # can't modify the request section
566: return 0;
567: }
568: }
569: }
570: #can't modify
571: return 0;
572: }
573:
574: sub canview {
575: my ($sec)=@_;
576: if ($perm{'vgr'}) {
577: if (!defined($perm{'vgr_section'})) {
578: # can modify whole class
579: return 1;
580: } else {
581: if ($sec eq $perm{'vgr_section'}) {
582: #can modify the requested section
583: return 1;
584: } else {
585: # can't modify the request section
586: return 0;
587: }
588: }
589: }
590: #can't modify
591: return 0;
592: }
593:
1.44 ng 594: #--- Retrieve the grade status of a student for all the parts
595: sub student_gradeStatus {
1.324 albertel 596: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 597: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 598: my %partstatus = ();
599: foreach (@$partlist) {
1.128 ng 600: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 601: $status = 'nothing' if ($status eq '');
602: $partstatus{$_} = $status;
603: my $subkey = "resource.$_.submitted_by";
604: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
605: }
606: return %partstatus;
607: }
608:
1.45 ng 609: # hidden form and javascript that calls the form
610: # Use by verifyscript and viewgrades
611: # Shows a student's view of problem and submission
612: sub jscriptNform {
1.324 albertel 613: my ($symb) = @_;
1.442 banghart 614: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 615: my $jscript='<script type="text/javascript" language="javascript">'."\n".
616: ' function viewOneStudent(user,domain) {'."\n".
617: ' document.onestudent.student.value = user;'."\n".
618: ' document.onestudent.userdom.value = domain;'."\n".
619: ' document.onestudent.submit();'."\n".
620: ' }'."\n".
621: '</script>'."\n";
622: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 623: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 624: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
625: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 626: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 627: '<input type="hidden" name="command" value="submission" />'."\n".
628: '<input type="hidden" name="student" value="" />'."\n".
629: '<input type="hidden" name="userdom" value="" />'."\n".
630: '</form>'."\n";
631: return $jscript;
632: }
1.39 ng 633:
1.447 foxr 634:
635:
1.315 bowersj2 636: # Given the score (as a number [0-1] and the weight) what is the final
637: # point value? This function will round to the nearest tenth, third,
638: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 639: sub compute_points {
1.315 bowersj2 640: my ($score, $weight) = @_;
641:
642: my $tolerance = .00001;
643: my $points = $score * $weight;
644:
645: # Check for nearness to 1/x.
646: my $check_for_nearness = sub {
647: my ($factor) = @_;
648: my $num = ($points * $factor) + $tolerance;
649: my $floored_num = floor($num);
1.316 albertel 650: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 651: return $floored_num / $factor;
652: }
653: return $points;
654: };
655:
656: $points = $check_for_nearness->(10);
657: $points = $check_for_nearness->(3);
658: $points = $check_for_nearness->(4);
659:
660: return $points;
661: }
662:
1.44 ng 663: #------------------ End of general use routines --------------------
1.87 www 664:
665: #
666: # Find most similar essay
667: #
668:
669: sub most_similar {
1.426 albertel 670: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 671:
672: # ignore spaces and punctuation
673:
674: $uessay=~s/\W+/ /gs;
675:
1.282 www 676: # ignore empty submissions (occuring when only files are sent)
677:
678: unless ($uessay=~/\w+/) { return ''; }
679:
1.87 www 680: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 681: my $limit=0.6;
1.87 www 682: my $sname='';
683: my $sdom='';
684: my $scrsid='';
685: my $sessay='';
686: # go through all essays ...
1.426 albertel 687: foreach my $tkey (keys(%$old_essays)) {
688: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 689: # ... except the same student
1.426 albertel 690: next if (($tname eq $uname) && ($tdom eq $udom));
691: my $tessay=$old_essays->{$tkey};
692: $tessay=~s/\W+/ /gs;
1.87 www 693: # String similarity gives up if not even limit
1.426 albertel 694: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 695: # Found one
1.426 albertel 696: if ($tsimilar>$limit) {
697: $limit=$tsimilar;
698: $sname=$tname;
699: $sdom=$tdom;
700: $scrsid=$tcrsid;
701: $sessay=$old_essays->{$tkey};
702: }
1.87 www 703: }
1.88 www 704: if ($limit>0.6) {
1.87 www 705: return ($sname,$sdom,$scrsid,$sessay,$limit);
706: } else {
707: return ('','','','',0);
708: }
709: }
710:
1.44 ng 711: #-------------------------------------------------------------------
712:
713: #------------------------------------ Receipt Verification Routines
1.45 ng 714: #
1.44 ng 715: #--- Check whether a receipt number is valid.---
716: sub verifyreceipt {
717: my $request = shift;
718:
1.257 albertel 719: my $courseid = $env{'request.course.id'};
1.184 www 720: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 721: $env{'form.receipt'};
1.44 ng 722: $receipt =~ s/[^\-\d]//g;
1.378 albertel 723: my ($symb) = &get_symb($request);
1.44 ng 724:
1.487 albertel 725: my $title.=
726: '<h3><span class="LC_info">'.
1.553 biermanm 727: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 728: '</span></h3>'."\n".
729: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
730: '</h4>'."\n";
1.44 ng 731:
732: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 733: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 734:
735: my $receiptparts=0;
1.390 albertel 736: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
737: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 738: my $parts=['0'];
1.324 albertel 739: if ($receiptparts) { ($parts)=&response_type($symb); }
1.486 albertel 740:
741: my $header =
742: &Apache::loncommon::start_data_table().
743: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 744: '<th> '.&mt('Fullname').' </th>'."\n".
745: '<th> '.&mt('Username').' </th>'."\n".
746: '<th> '.&mt('Domain').' </th>';
1.486 albertel 747: if ($receiptparts) {
1.487 albertel 748: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 749: }
750: $header.=
751: &Apache::loncommon::end_data_table_header_row();
752:
1.294 albertel 753: foreach (sort
754: {
755: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
756: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
757: }
758: return $a cmp $b;
759: } (keys(%$fullname))) {
1.44 ng 760: my ($uname,$udom)=split(/\:/);
1.177 albertel 761: foreach my $part (@$parts) {
762: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 763: $contents.=
764: &Apache::loncommon::start_data_table_row().
765: '<td> '."\n".
1.177 albertel 766: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 767: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 768: '<td> '.$uname.' </td>'.
769: '<td> '.$udom.' </td>';
770: if ($receiptparts) {
771: $contents.='<td> '.$part.' </td>';
772: }
1.486 albertel 773: $contents.=
774: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 775:
776: $matches++;
777: }
1.44 ng 778: }
779: }
780: if ($matches == 0) {
1.487 albertel 781: $string = $title.&mt('No match found for the above receipt.');
1.44 ng 782: } else {
1.324 albertel 783: $string = &jscriptNform($symb).$title.
1.487 albertel 784: '<p>'.
785: &mt('The above receipt matches the following [numerate,_1,student].',$matches).
786: '</p>'.
1.486 albertel 787: $header.
788: $contents.
789: &Apache::loncommon::end_data_table()."\n";
1.44 ng 790: }
1.324 albertel 791: return $string.&show_grading_menu_form($symb);
1.44 ng 792: }
793:
794: #--- This is called by a number of programs.
795: #--- Called from the Grading Menu - View/Grade an individual student
796: #--- Also called directly when one clicks on the subm button
797: # on the problem page.
1.30 ng 798: sub listStudents {
1.41 ng 799: my ($request) = shift;
1.49 albertel 800:
1.324 albertel 801: my ($symb) = &get_symb($request);
1.257 albertel 802: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
803: my $cnum = $env{"course.$env{'request.course.id'}.num"};
804: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 805: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 806: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 807: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 808: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
809: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 810:
1.548 bisitz 811: my $result='<h3><span class="LC_info"> '
812: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 813: .'</span></h3>';
1.118 ng 814:
1.324 albertel 815: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 816:
1.485 albertel 817: my %lt = ( 'multiple' =>
1.539 riegler 818: &mt("Please select a student or group of students before clicking on the Next button."),
1.485 albertel 819: 'single' =>
1.539 riegler 820: &mt("Please select the student before clicking on the Next button."),
1.485 albertel 821: );
822: %lt = &Apache::lonlocal::texthash(%lt);
1.45 ng 823: $request->print(<<LISTJAVASCRIPT);
824: <script type="text/javascript" language="javascript">
1.110 ng 825: function checkSelect(checkBox) {
826: var ctr=0;
827: var sense="";
828: if (checkBox.length > 1) {
829: for (var i=0; i<checkBox.length; i++) {
830: if (checkBox[i].checked) {
831: ctr++;
832: }
833: }
1.485 albertel 834: sense = '$lt{'multiple'}';
1.110 ng 835: } else {
836: if (checkBox.checked) {
837: ctr = 1;
838: }
1.485 albertel 839: sense = '$lt{'single'}';
1.110 ng 840: }
841: if (ctr == 0) {
1.485 albertel 842: alert(sense);
1.110 ng 843: return false;
844: }
845: document.gradesub.submit();
846: }
847:
848: function reLoadList(formname) {
1.112 ng 849: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 850: formname.command.value = 'submission';
851: formname.submit();
852: }
1.45 ng 853: </script>
854: LISTJAVASCRIPT
855:
1.118 ng 856: &commonJSfunctions($request);
1.41 ng 857: $request->print($result);
1.39 ng 858:
1.401 albertel 859: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
860: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 861: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 862: "\n".$table;
863:
864: $gradeTable .=
1.539 riegler 865: ' <b>'.&mt('View Problem Text').': </b>'.
1.485 albertel 866: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
867: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n".
1.539 riegler 868: '<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n";
1.485 albertel 869: $gradeTable .=
1.539 riegler 870: ' <b>'.&mt('View Answer').': </b>'.
1.485 albertel 871: '<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n".
872: '<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n".
1.539 riegler 873: '<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n";
1.485 albertel 874:
875: my $submission_options;
1.257 albertel 876: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 877: $submission_options.=
878: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 879: }
1.442 banghart 880: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
881: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 882: $env{'form.Status'} = $saveStatus;
1.485 albertel 883: $submission_options.=
884: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.&mt('last submission only').' </label>'."\n".
885: '<label><input type="radio" name="lastSub" value="last" /> '.&mt('last submission & parts info').' </label>'."\n".
886: '<label><input type="radio" name="lastSub" value="datesub" /> '.&mt('by dates and submissions').' </label>'."\n".
887: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').'</label>';
888: $gradeTable .=
1.539 riegler 889: ' <b>'.&mt('Submissions').': </b>'.$submission_options.'<br />'."\n";
1.485 albertel 890:
891: $gradeTable .=
1.539 riegler 892: ' <b>'.&mt('Grading Increments').': </b>'.
1.485 albertel 893: '<select name="increment">'.
894: '<option value="1">'.&mt('Whole Points').'</option>'.
895: '<option value=".5">'.&mt('Half Points').'</option>'.
896: '<option value=".25">'.&mt('Quarter Points').'</option>'.
897: '<option value=".1">'.&mt('Tenths of a Point').'</option>'.
1.539 riegler 898: '</select>';
1.485 albertel 899:
900: $gradeTable .=
1.432 banghart 901: &build_section_inputs().
1.45 ng 902: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 903: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
904: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
905: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
906: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 907: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 908: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
909:
1.257 albertel 910: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.442 banghart 911: $gradeTable.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 912: } else {
1.485 albertel 913: $gradeTable.=&mt('<b>Student Status:</b> [_1]',
914: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);')).'<br />';
1.124 ng 915: }
1.112 ng 916:
1.548 bisitz 917: $gradeTable.=&mt('To '.lc($viewgrade)." 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.").'<br />'."\n".
1.110 ng 918: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 919:
920: # checkall buttons
921: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 922: $gradeTable.='<input type="button" '."\n".
1.45 ng 923: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.539 riegler 924: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 925: $gradeTable.=&check_buttons();
1.485 albertel 926: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="checked" />'.&mt('Check For Plagiarism').'</label>';
1.450 banghart 927: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 928: $gradeTable.= &Apache::loncommon::start_data_table().
929: &Apache::loncommon::start_data_table_header_row();
1.110 ng 930: my $loop = 0;
931: while ($loop < 2) {
1.485 albertel 932: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
933: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 934: if ($env{'form.showgrading'} eq 'yes'
935: && $submitonly ne 'queued'
936: && $submitonly ne 'all') {
1.485 albertel 937: foreach my $part (sort(@$partlist)) {
938: my $display_part=
939: &get_display_part((split(/_/,$part))[0],$symb);
940: $gradeTable.=
941: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 942: }
1.301 albertel 943: } elsif ($submitonly eq 'queued') {
1.474 albertel 944: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 945: }
946: $loop++;
1.126 ng 947: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 948: }
1.474 albertel 949: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 950:
1.45 ng 951: my $ctr = 0;
1.294 albertel 952: foreach my $student (sort
953: {
954: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
955: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
956: }
957: return $a cmp $b;
958: }
959: (keys(%$fullname))) {
1.41 ng 960: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 961:
1.110 ng 962: my %status = ();
1.301 albertel 963:
964: if ($submitonly eq 'queued') {
965: my %queue_status =
966: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
967: $udom,$uname);
968: next if (!defined($queue_status{'gradingqueue'}));
969: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
970: }
971:
972: if ($env{'form.showgrading'} eq 'yes'
973: && $submitonly ne 'queued'
974: && $submitonly ne 'all') {
1.324 albertel 975: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 976: my $submitted = 0;
1.164 albertel 977: my $graded = 0;
1.248 albertel 978: my $incorrect = 0;
1.110 ng 979: foreach (keys(%status)) {
1.145 albertel 980: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 981: $graded = 1 if ($status{$_} =~ /^ungraded/);
982: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
983:
1.110 ng 984: my ($foo,$partid,$foo1) = split(/\./,$_);
985: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 986: $submitted = 0;
1.150 albertel 987: my ($part)=split(/\./,$partid);
1.110 ng 988: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 989: $student.':'.$part.':submitted_by" value="'.
1.110 ng 990: $status{'resource.'.$partid.'.submitted_by'}.'" />';
991: }
1.41 ng 992: }
1.248 albertel 993:
1.156 albertel 994: next if (!$submitted && ($submitonly eq 'yes' ||
995: $submitonly eq 'incorrect' ||
996: $submitonly eq 'graded'));
1.248 albertel 997: next if (!$graded && ($submitonly eq 'graded'));
998: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 999: }
1.34 ng 1000:
1.45 ng 1001: $ctr++;
1.249 albertel 1002: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1003: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1004: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1005: if ($ctr%2 ==1) {
1006: $gradeTable.= &Apache::loncommon::start_data_table_row();
1007: }
1.126 ng 1008: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 1009: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
1010: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1011: ') " /> </label></td>'."\n".'<td>'.
1012: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1013: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1014:
1.257 albertel 1015: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1016: foreach (sort(keys(%status))) {
1.485 albertel 1017: next if ($_ =~ /^resource.*?submitted_by$/);
1018: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1019: }
1.41 ng 1020: }
1.126 ng 1021: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1022: if ($ctr%2 ==0) {
1023: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1024: }
1.41 ng 1025: }
1026: }
1.110 ng 1027: if ($ctr%2 ==1) {
1.126 ng 1028: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1029: if ($env{'form.showgrading'} eq 'yes'
1030: && $submitonly ne 'queued'
1031: && $submitonly ne 'all') {
1.110 ng 1032: foreach (@$partlist) {
1033: $gradeTable.='<td> </td>';
1034: }
1.301 albertel 1035: } elsif ($submitonly eq 'queued') {
1036: $gradeTable.='<td> </td>';
1.110 ng 1037: }
1.474 albertel 1038: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1039: }
1040:
1.474 albertel 1041: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.45 ng 1042: '<input type="button" '.
1043: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.539 riegler 1044: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1045: if ($ctr == 0) {
1.96 albertel 1046: my $num_students=(scalar(keys(%$fullname)));
1047: if ($num_students eq 0) {
1.485 albertel 1048: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1049: } else {
1.171 albertel 1050: my $submissions='submissions';
1051: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1052: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1053: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1054: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1055: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1056: $num_students).
1057: '</span><br />';
1.96 albertel 1058: }
1.46 ng 1059: } elsif ($ctr == 1) {
1.474 albertel 1060: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1061: }
1.324 albertel 1062: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1063: $request->print($gradeTable);
1.44 ng 1064: return '';
1.10 ng 1065: }
1066:
1.44 ng 1067: #---- Called from the listStudents routine
1.249 albertel 1068:
1069: sub check_script {
1070: my ($form, $type)=@_;
1071: my $chkallscript='<script type="text/javascript">
1072: function checkall() {
1073: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1074: ele = document.forms.'.$form.'.elements[i];
1075: if (ele.name == "'.$type.'") {
1076: document.forms.'.$form.'.elements[i].checked=true;
1077: }
1078: }
1079: }
1080:
1081: function checksec() {
1082: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1083: ele = document.forms.'.$form.'.elements[i];
1084: string = document.forms.'.$form.'.chksec.value;
1085: if
1086: (ele.value.indexOf(":::SECTION"+string)>0) {
1087: document.forms.'.$form.'.elements[i].checked=true;
1088: }
1089: }
1090: }
1091:
1092:
1093: function uncheckall() {
1094: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1095: ele = document.forms.'.$form.'.elements[i];
1096: if (ele.name == "'.$type.'") {
1097: document.forms.'.$form.'.elements[i].checked=false;
1098: }
1099: }
1100: }
1101:
1102: </script>'."\n";
1103: return $chkallscript;
1104: }
1105:
1106: sub check_buttons {
1.485 albertel 1107: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1108: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1109: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1110: $buttons.='<input type="text" size="5" name="chksec" /> ';
1111: return $buttons;
1112: }
1113:
1.44 ng 1114: # Displays the submissions for one student or a group of students
1.34 ng 1115: sub processGroup {
1.41 ng 1116: my ($request) = shift;
1117: my $ctr = 0;
1.155 albertel 1118: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1119: my $total = scalar(@stuchecked)-1;
1.45 ng 1120:
1.396 banghart 1121: foreach my $student (@stuchecked) {
1122: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1123: $env{'form.student'} = $uname;
1124: $env{'form.userdom'} = $udom;
1125: $env{'form.fullname'} = $fullname;
1.41 ng 1126: &submission($request,$ctr,$total);
1127: $ctr++;
1128: }
1129: return '';
1.35 ng 1130: }
1.34 ng 1131:
1.44 ng 1132: #------------------------------------------------------------------------------------
1133: #
1134: #-------------------------- Next few routines handles grading by student, essentially
1135: # handles essay response type problem/part
1136: #
1137: #--- Javascript to handle the submission page functionality ---
1138: sub sub_page_js {
1139: my $request = shift;
1.539 riegler 1140: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1141: $request->print(<<SUBJAVASCRIPT);
1142: <script type="text/javascript" language="javascript">
1.71 ng 1143: function updateRadio(formname,id,weight) {
1.125 ng 1144: var gradeBox = formname["GD_BOX"+id];
1145: var radioButton = formname["RADVAL"+id];
1146: var oldpts = formname["oldpts"+id].value;
1.72 ng 1147: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1148: gradeBox.value = pts;
1149: var resetbox = false;
1150: if (isNaN(pts) || pts < 0) {
1.539 riegler 1151: alert("$alertmsg"+pts);
1.71 ng 1152: for (var i=0; i<radioButton.length; i++) {
1153: if (radioButton[i].checked) {
1154: gradeBox.value = i;
1155: resetbox = true;
1156: }
1157: }
1158: if (!resetbox) {
1159: formtextbox.value = "";
1160: }
1161: return;
1.44 ng 1162: }
1.71 ng 1163:
1164: if (pts > weight) {
1165: var resp = confirm("You entered a value ("+pts+
1166: ") greater than the weight for the part. Accept?");
1167: if (resp == false) {
1.125 ng 1168: gradeBox.value = oldpts;
1.71 ng 1169: return;
1170: }
1.44 ng 1171: }
1.13 albertel 1172:
1.71 ng 1173: for (var i=0; i<radioButton.length; i++) {
1174: radioButton[i].checked=false;
1175: if (pts == i && pts != "") {
1176: radioButton[i].checked=true;
1177: }
1178: }
1179: updateSelect(formname,id);
1.125 ng 1180: formname["stores"+id].value = "0";
1.41 ng 1181: }
1.5 albertel 1182:
1.72 ng 1183: function writeBox(formname,id,pts) {
1.125 ng 1184: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1185: if (checkSolved(formname,id) == 'update') {
1186: gradeBox.value = pts;
1187: } else {
1.125 ng 1188: var oldpts = formname["oldpts"+id].value;
1.72 ng 1189: gradeBox.value = oldpts;
1.125 ng 1190: var radioButton = formname["RADVAL"+id];
1.71 ng 1191: for (var i=0; i<radioButton.length; i++) {
1192: radioButton[i].checked=false;
1.72 ng 1193: if (i == oldpts) {
1.71 ng 1194: radioButton[i].checked=true;
1195: }
1196: }
1.41 ng 1197: }
1.125 ng 1198: formname["stores"+id].value = "0";
1.71 ng 1199: updateSelect(formname,id);
1200: return;
1.41 ng 1201: }
1.44 ng 1202:
1.71 ng 1203: function clearRadBox(formname,id) {
1204: if (checkSolved(formname,id) == 'noupdate') {
1205: updateSelect(formname,id);
1206: return;
1207: }
1.125 ng 1208: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1209: for (var i=0; i<gradeSelect.length; i++) {
1210: if (gradeSelect[i].selected) {
1211: var selectx=i;
1212: }
1213: }
1.125 ng 1214: var stores = formname["stores"+id];
1.71 ng 1215: if (selectx == stores.value) { return };
1.125 ng 1216: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1217: gradeBox.value = "";
1.125 ng 1218: var radioButton = formname["RADVAL"+id];
1.71 ng 1219: for (var i=0; i<radioButton.length; i++) {
1220: radioButton[i].checked=false;
1221: }
1222: stores.value = selectx;
1223: }
1.5 albertel 1224:
1.71 ng 1225: function checkSolved(formname,id) {
1.125 ng 1226: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1227: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1228: if (!reply) {return "noupdate";}
1.120 ng 1229: formname.overRideScore.value = 'yes';
1.41 ng 1230: }
1.71 ng 1231: return "update";
1.13 albertel 1232: }
1.71 ng 1233:
1234: function updateSelect(formname,id) {
1.125 ng 1235: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1236: return;
1.41 ng 1237: }
1.33 ng 1238:
1.121 ng 1239: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1240: function checksubmit(formname,val,total,parttot) {
1.121 ng 1241: formname.gradeOpt.value = val;
1.71 ng 1242: if (val == "Save & Next") {
1243: for (i=0;i<=total;i++) {
1244: for (j=0;j<parttot;j++) {
1.125 ng 1245: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1246: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1247: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1248: if (points == "") {
1.125 ng 1249: var name = formname["name"+i].value;
1.129 ng 1250: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1251: var resp = confirm("You did not assign a score for "+studentID+
1252: ", part "+partid+". Continue?");
1.71 ng 1253: if (resp == false) {
1.125 ng 1254: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1255: return false;
1256: }
1257: }
1258: }
1259:
1260: }
1261: }
1262:
1263: }
1.121 ng 1264: if (val == "Grade Student") {
1265: formname.showgrading.value = "yes";
1266: if (formname.Status.value == "") {
1267: formname.Status.value = "Active";
1268: }
1269: formname.studentNo.value = total;
1270: }
1.120 ng 1271: formname.submit();
1272: }
1273:
1.71 ng 1274: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1275: function checkSubmitPage(formname,total) {
1276: noscore = new Array(100);
1277: var ptr = 0;
1278: for (i=1;i<total;i++) {
1.125 ng 1279: var partid = formname["q_"+i].value;
1.127 ng 1280: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1281: var points = formname["GD_BOX"+i+"_"+partid].value;
1282: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1283: if (points == "" && status != "correct_by_student") {
1284: noscore[ptr] = i;
1285: ptr++;
1286: }
1287: }
1288: }
1289: if (ptr != 0) {
1290: var sense = ptr == 1 ? ": " : "s: ";
1291: var prolist = "";
1292: if (ptr == 1) {
1293: prolist = noscore[0];
1294: } else {
1295: var i = 0;
1296: while (i < ptr-1) {
1297: prolist += noscore[i]+", ";
1298: i++;
1299: }
1300: prolist += "and "+noscore[i];
1301: }
1302: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1303: if (resp == false) {
1304: return false;
1305: }
1306: }
1.45 ng 1307:
1.71 ng 1308: formname.submit();
1309: }
1310: </script>
1311: SUBJAVASCRIPT
1312: }
1.45 ng 1313:
1.71 ng 1314: #--- javascript for essay type problem --
1315: sub sub_page_kw_js {
1316: my $request = shift;
1.80 ng 1317: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1318: &commonJSfunctions($request);
1.350 albertel 1319:
1.351 albertel 1320: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1321: <script text="text/javascript">
1322: function checkInput() {
1323: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1324: var nmsg = opener.document.SCORE.savemsgN.value;
1325: var usrctr = document.msgcenter.usrctr.value;
1326: var newval = opener.document.SCORE["newmsg"+usrctr];
1327: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1328:
1329: var msgchk = "";
1330: if (document.msgcenter.subchk.checked) {
1331: msgchk = "msgsub,";
1332: }
1333: var includemsg = 0;
1334: for (var i=1; i<=nmsg; i++) {
1335: var opnmsg = opener.document.SCORE["savemsg"+i];
1336: var frmmsg = document.msgcenter["msg"+i];
1337: opnmsg.value = opener.checkEntities(frmmsg.value);
1338: var showflg = opener.document.SCORE["shownOnce"+i];
1339: showflg.value = "1";
1340: var chkbox = document.msgcenter["msgn"+i];
1341: if (chkbox.checked) {
1342: msgchk += "savemsg"+i+",";
1343: includemsg = 1;
1344: }
1345: }
1346: if (document.msgcenter.newmsgchk.checked) {
1347: msgchk += "newmsg"+usrctr;
1348: includemsg = 1;
1349: }
1350: imgformname = opener.document.SCORE["mailicon"+usrctr];
1351: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1352: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1353: includemsg.value = msgchk;
1354:
1355: self.close()
1356:
1357: }
1358: </script>
1359: INNERJS
1360:
1.351 albertel 1361: my $inner_js_highlight_central=<<INNERJS;
1362: <script type="text/javascript">
1363: function updateChoice(flag) {
1364: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1365: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1366: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1367: opener.document.SCORE.refresh.value = "on";
1368: if (opener.document.SCORE.keywords.value!=""){
1369: opener.document.SCORE.submit();
1370: }
1371: self.close()
1372: }
1373: </script>
1374: INNERJS
1375:
1376: my $start_page_msg_central =
1377: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1378: {'js_ready' => 1,
1379: 'only_body' => 1,
1380: 'bgcolor' =>'#FFFFFF',});
1381: my $end_page_msg_central =
1382: &Apache::loncommon::end_page({'js_ready' => 1});
1383:
1384:
1385: my $start_page_highlight_central =
1386: &Apache::loncommon::start_page('Highlight Central',
1387: $inner_js_highlight_central,
1.350 albertel 1388: {'js_ready' => 1,
1389: 'only_body' => 1,
1390: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1391: my $end_page_highlight_central =
1.350 albertel 1392: &Apache::loncommon::end_page({'js_ready' => 1});
1393:
1.219 www 1394: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1395: $docopen=~s/^document\.//;
1.539 riegler 1396: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.71 ng 1397: $request->print(<<SUBJAVASCRIPT);
1398: <script type="text/javascript" language="javascript">
1.45 ng 1399:
1.44 ng 1400: //===================== Show list of keywords ====================
1.122 ng 1401: function keywords(formname) {
1402: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1403: if (nret==null) return;
1.122 ng 1404: formname.keywords.value = nret;
1.44 ng 1405:
1.122 ng 1406: if (formname.keywords.value != "") {
1.128 ng 1407: formname.refresh.value = "on";
1.122 ng 1408: formname.submit();
1.44 ng 1409: }
1410: return;
1411: }
1412:
1413: //===================== Script to view submitted by ==================
1414: function viewSubmitter(submitter) {
1415: document.SCORE.refresh.value = "on";
1416: document.SCORE.NCT.value = "1";
1417: document.SCORE.unamedom0.value = submitter;
1418: document.SCORE.submit();
1419: return;
1420: }
1421:
1422: //===================== Script to add keyword(s) ==================
1423: function getSel() {
1424: if (document.getSelection) txt = document.getSelection();
1425: else if (document.selection) txt = document.selection.createRange().text;
1426: else return;
1427: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1428: if (cleantxt=="") {
1.539 riegler 1429: alert("$alertmsg");
1.44 ng 1430: return;
1431: }
1432: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1433: if (nret==null) return;
1.127 ng 1434: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1435: if (document.SCORE.keywords.value != "") {
1.127 ng 1436: document.SCORE.refresh.value = "on";
1.44 ng 1437: document.SCORE.submit();
1438: }
1439: return;
1440: }
1441:
1442: //====================== Script for composing message ==============
1.80 ng 1443: // preload images
1444: img1 = new Image();
1445: img1.src = "$iconpath/mailbkgrd.gif";
1446: img2 = new Image();
1447: img2.src = "$iconpath/mailto.gif";
1448:
1.44 ng 1449: function msgCenter(msgform,usrctr,fullname) {
1450: var Nmsg = msgform.savemsgN.value;
1451: savedMsgHeader(Nmsg,usrctr,fullname);
1452: var subject = msgform.msgsub.value;
1.127 ng 1453: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1454: re = /msgsub/;
1455: var shwsel = "";
1456: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1457: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1458: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1459: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1460: var testmsg = "savemsg"+i+",";
1461: re = new RegExp(testmsg,"g");
1.44 ng 1462: shwsel = "";
1463: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1464: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1465: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1466: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1467: //any < is already converted to <, etc. However, only once!!
1.44 ng 1468: }
1.125 ng 1469: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1470: shwsel = "";
1471: re = /newmsg/;
1472: if (re.test(msgchk)) { shwsel = "checked" }
1473: newMsg(newmsg,shwsel);
1474: msgTail();
1475: return;
1476: }
1477:
1.123 ng 1478: function checkEntities(strx) {
1479: if (strx.length == 0) return strx;
1480: var orgStr = ["&", "<", ">", '"'];
1481: var newStr = ["&", "<", ">", """];
1482: var counter = 0;
1483: while (counter < 4) {
1484: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1485: counter++;
1486: }
1487: return strx;
1488: }
1489:
1490: function strReplace(strx, orgStr, newStr) {
1491: return strx.split(orgStr).join(newStr);
1492: }
1493:
1.44 ng 1494: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1495: var height = 70*Nmsg+250;
1.44 ng 1496: var scrollbar = "no";
1497: if (height > 600) {
1498: height = 600;
1499: scrollbar = "yes";
1500: }
1.118 ng 1501: var xpos = (screen.width-600)/2;
1502: xpos = (xpos < 0) ? '0' : xpos;
1503: var ypos = (screen.height-height)/2-30;
1504: ypos = (ypos < 0) ? '0' : ypos;
1505:
1.206 albertel 1506: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1507: pWin.focus();
1508: pDoc = pWin.document;
1.219 www 1509: pDoc.$docopen;
1.351 albertel 1510: pDoc.write('$start_page_msg_central');
1.76 ng 1511:
1512: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1513: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1514: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1515:
1516: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1517: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1.465 albertel 1518: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1519: }
1520: function displaySubject(msg,shwsel) {
1.76 ng 1521: pDoc = pWin.document;
1522: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1523: pDoc.write("<td>Subject<\\/td>");
1524: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1525: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1526: }
1527:
1.72 ng 1528: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1529: pDoc = pWin.document;
1530: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1531: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1532: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1533: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1534: }
1535:
1536: function newMsg(newmsg,shwsel) {
1.76 ng 1537: pDoc = pWin.document;
1538: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1539: pDoc.write("<td align=\\"center\\">New<\\/td>");
1540: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1541: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1542: }
1543:
1544: function msgTail() {
1.76 ng 1545: pDoc = pWin.document;
1.465 albertel 1546: pDoc.write("<\\/table>");
1547: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1548: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1549: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1550: pDoc.write("<\\/form>");
1.351 albertel 1551: pDoc.write('$end_page_msg_central');
1.128 ng 1552: pDoc.close();
1.44 ng 1553: }
1554:
1555: //====================== Script for keyword highlight options ==============
1556: function kwhighlight() {
1557: var kwclr = document.SCORE.kwclr.value;
1558: var kwsize = document.SCORE.kwsize.value;
1559: var kwstyle = document.SCORE.kwstyle.value;
1560: var redsel = "";
1561: var grnsel = "";
1562: var blusel = "";
1563: if (kwclr=="red") {var redsel="checked"};
1564: if (kwclr=="green") {var grnsel="checked"};
1565: if (kwclr=="blue") {var blusel="checked"};
1566: var sznsel = "";
1567: var sz1sel = "";
1568: var sz2sel = "";
1569: if (kwsize=="0") {var sznsel="checked"};
1570: if (kwsize=="+1") {var sz1sel="checked"};
1571: if (kwsize=="+2") {var sz2sel="checked"};
1572: var synsel = "";
1573: var syisel = "";
1574: var sybsel = "";
1575: if (kwstyle=="") {var synsel="checked"};
1576: if (kwstyle=="<i>") {var syisel="checked"};
1577: if (kwstyle=="<b>") {var sybsel="checked"};
1578: highlightCentral();
1579: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1580: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1581: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1582: highlightend();
1583: return;
1584: }
1585:
1586: function highlightCentral() {
1.76 ng 1587: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1588: var xpos = (screen.width-400)/2;
1589: xpos = (xpos < 0) ? '0' : xpos;
1590: var ypos = (screen.height-330)/2-30;
1591: ypos = (ypos < 0) ? '0' : ypos;
1592:
1.206 albertel 1593: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1594: hwdWin.focus();
1595: var hDoc = hwdWin.document;
1.219 www 1596: hDoc.$docopen;
1.351 albertel 1597: hDoc.write('$start_page_highlight_central');
1.76 ng 1598: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1599: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1600:
1601: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1602: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1.465 albertel 1603: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1604: }
1605:
1606: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1607: var hDoc = hwdWin.document;
1608: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1609: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1610: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1611: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1612: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1613: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1614: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1615: hDoc.write("<\\/tr>");
1.44 ng 1616: }
1617:
1618: function highlightend() {
1.76 ng 1619: var hDoc = hwdWin.document;
1.465 albertel 1620: hDoc.write("<\\/table>");
1621: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1622: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1623: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1624: hDoc.write("<\\/form>");
1.351 albertel 1625: hDoc.write('$end_page_highlight_central');
1.128 ng 1626: hDoc.close();
1.44 ng 1627: }
1628:
1629: </script>
1630: SUBJAVASCRIPT
1631: }
1632:
1.349 albertel 1633: sub get_increment {
1.348 bowersj2 1634: my $increment = $env{'form.increment'};
1635: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1636: $increment != .1) {
1637: $increment = 1;
1638: }
1639: return $increment;
1640: }
1641:
1.71 ng 1642: #--- displays the grading box, used in essay type problem and grading by page/sequence
1643: sub gradeBox {
1.322 albertel 1644: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1645: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1646: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1647: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1648: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1649: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1650: $wgt = ($wgt > 0 ? $wgt : '1');
1651: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1652: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1653: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1654: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1655: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1656: [$partid]);
1657: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1658: if ($last_resets{$partid}) {
1659: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1660: }
1.485 albertel 1661: $result.='<table border="0"><tr>';
1.71 ng 1662: my $ctr = 0;
1.348 bowersj2 1663: my $thisweight = 0;
1.349 albertel 1664: my $increment = &get_increment();
1.485 albertel 1665:
1666: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1667: while ($thisweight<=$wgt) {
1.532 bisitz 1668: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1669: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1670: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1671: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1672: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1673: $thisweight += $increment;
1.71 ng 1674: $ctr++;
1675: }
1.485 albertel 1676: $radio.='</tr></table>';
1677:
1678: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1679: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1680: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1681: $wgt.')" /></td>'."\n";
1.485 albertel 1682: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1683: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.540 riegler 1684: ' </td><td><b>'.&mt('Grade Status').':</b>'."\n";
1.485 albertel 1685: $line.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.71 ng 1686: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1687: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1688: $line.='<option></option>'.
1689: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1690: } else {
1.485 albertel 1691: $line.='<option selected="selected"></option>'.
1692: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1693: }
1.485 albertel 1694: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1695:
1696:
1.540 riegler 1697: #&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 1698: $result .=
1.540 riegler 1699: '<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 1700:
1701: $result.='</tr></table>'."\n";
1.71 ng 1702: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1703: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1704: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1705: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1706: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1707: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1708: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1709: $aggtries.'" />'."\n";
1.323 banghart 1710: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1711: return $result;
1712: }
1.322 albertel 1713:
1714: sub handback_box {
1.323 banghart 1715: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1716: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1717: my (@respids);
1.375 albertel 1718: my @part_response_id = &flatten_responseType($responseType);
1719: foreach my $part_response_id (@part_response_id) {
1720: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1721: if ($part eq $partid) {
1.375 albertel 1722: push(@respids,$resp);
1.323 banghart 1723: }
1724: }
1.318 banghart 1725: my $result;
1.323 banghart 1726: foreach my $respid (@respids) {
1.322 albertel 1727: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1728: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1729: next if (!@$files);
1730: my $file_counter = 1;
1.313 banghart 1731: foreach my $file (@$files) {
1.368 banghart 1732: if ($file =~ /\/portfolio\//) {
1733: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1734: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1735: $file_disp = "$name.$ext";
1736: $file = $file_path.$file_disp;
1737: $result.=&mt('Return commented version of [_1] to student.',
1738: '<span class="LC_filename">'.$file_disp.'</span>');
1739: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1740: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1741: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1742: $file_counter++;
1743: }
1.322 albertel 1744: }
1.313 banghart 1745: }
1.318 banghart 1746: return $result;
1.71 ng 1747: }
1.44 ng 1748:
1.58 albertel 1749: sub show_problem {
1.382 albertel 1750: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1751: my $rendered;
1.382 albertel 1752: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1753: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1754: if ($mode eq 'both' or $mode eq 'text') {
1755: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1756: $env{'request.course.id'},
1757: undef,\%form);
1.144 albertel 1758: }
1.58 albertel 1759: if ($removeform) {
1760: $rendered=~s|<form(.*?)>||g;
1761: $rendered=~s|</form>||g;
1.374 albertel 1762: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1763: }
1.144 albertel 1764: my $companswer;
1765: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1766: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1767: $companswer=
1768: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1769: $env{'request.course.id'},
1770: %form);
1.144 albertel 1771: }
1.58 albertel 1772: if ($removeform) {
1773: $companswer=~s|<form(.*?)>||g;
1774: $companswer=~s|</form>||g;
1.144 albertel 1775: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1776: }
1.468 albertel 1777: $rendered=
1778: '<div class="LC_grade_show_problem_header">'.
1779: &mt('View of the problem').
1780: '</div><div class="LC_grade_show_problem_problem">'.
1781: $rendered.
1782: '</div>';
1783: $companswer=
1784: '<div class="LC_grade_show_problem_header">'.
1785: &mt('Correct answer').
1786: '</div><div class="LC_grade_show_problem_problem">'.
1787: $companswer.
1788: '</div>';
1789: my $result;
1.144 albertel 1790: if ($mode eq 'both') {
1.468 albertel 1791: $result=$rendered.$companswer;
1.144 albertel 1792: } elsif ($mode eq 'text') {
1.468 albertel 1793: $result=$rendered;
1.144 albertel 1794: } elsif ($mode eq 'answer') {
1.468 albertel 1795: $result=$companswer;
1.144 albertel 1796: }
1.468 albertel 1797: $result='<div class="LC_grade_show_problem">'.$result.'</div>';
1.71 ng 1798: return $result;
1.58 albertel 1799: }
1.397 albertel 1800:
1.396 banghart 1801: sub files_exist {
1802: my ($r, $symb) = @_;
1803: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1804:
1.396 banghart 1805: foreach my $student (@students) {
1806: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1807: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1808: $udom,$uname);
1.396 banghart 1809: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1810: foreach my $submission (@$string) {
1811: my ($partid,$respid) =
1812: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1813: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1814: \%record);
1815: return 1 if (@$files);
1.396 banghart 1816: }
1817: }
1.397 albertel 1818: return 0;
1.396 banghart 1819: }
1.397 albertel 1820:
1.394 banghart 1821: sub download_all_link {
1822: my ($r,$symb) = @_;
1.395 albertel 1823: my $all_students =
1824: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1825:
1826: my $parts =
1827: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1828:
1.394 banghart 1829: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1830: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1831: 'cgi.'.$identifier.'.symb' => $symb,
1832: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1833: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1834: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1835: return
1836: }
1.395 albertel 1837:
1.432 banghart 1838: sub build_section_inputs {
1839: my $section_inputs;
1840: if ($env{'form.section'} eq '') {
1841: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1842: } else {
1843: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1844: foreach my $section (@sections) {
1.432 banghart 1845: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1846: }
1847: }
1848: return $section_inputs;
1849: }
1850:
1.44 ng 1851: # --------------------------- show submissions of a student, option to grade
1852: sub submission {
1853: my ($request,$counter,$total) = @_;
1.257 albertel 1854: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1855: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1856: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1857: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1858: my $symb = &get_symb($request);
1859: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1860:
1861: if (!&canview($usec)) {
1.398 albertel 1862: $request->print('<span class="LC_warning">Unable to view requested student.('.
1863: $uname.':'.$udom.' in section '.$usec.' in course id '.
1864: $env{'request.course.id'}.')</span>');
1.324 albertel 1865: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1866: return;
1867: }
1868:
1.257 albertel 1869: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1870: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1871: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1872: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1873: my $checkIcon = '<img alt="'.&mt('Check Mark').
1874: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1875: '/check.gif" height="16" border="0" />';
1.41 ng 1876:
1.426 albertel 1877: my %old_essays;
1.41 ng 1878: # header info
1879: if ($counter == 0) {
1880: &sub_page_js($request);
1.257 albertel 1881: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1882: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1883: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1884: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1885: &download_all_link($request, $symb);
1886: }
1.485 albertel 1887: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1888: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 1889:
1.44 ng 1890: # option to display problem, only once else it cause problems
1891: # with the form later since the problem has a form.
1.257 albertel 1892: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1893: my $mode;
1.257 albertel 1894: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1895: $mode='both';
1.257 albertel 1896: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1897: $mode='text';
1.257 albertel 1898: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1899: $mode='answer';
1900: }
1.329 albertel 1901: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1902: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1903: }
1.441 www 1904:
1.44 ng 1905: # kwclr is the only variable that is guaranteed to be non blank
1906: # if this subroutine has been called once.
1.41 ng 1907: my %keyhash = ();
1.257 albertel 1908: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1909: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1910: $env{'course.'.$env{'request.course.id'}.'.domain'},
1911: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1912:
1.257 albertel 1913: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1914: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1915: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1916: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1917: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1918: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1919: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1920: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1921: }
1.257 albertel 1922: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1923: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1924: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1925: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1926: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 1927: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 1928: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1929: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1930: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1931: '<input type="hidden" name="studentNo" value="" />'."\n".
1932: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1933: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1934: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1935: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1936: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1937: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 1938: &build_section_inputs().
1.326 albertel 1939: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1940: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1941: '<input type="hidden" name="NCT"'.
1.257 albertel 1942: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1943: if ($env{'form.handgrade'} eq 'yes') {
1944: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1945: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1946: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1947: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1948: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1949: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1950: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1951: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1952: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1953: }
1.123 ng 1954: }
1.41 ng 1955:
1956: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1957: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1958: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1959: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1960: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1961: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1962: '" />'."\n".
1963: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1964: $cts++;
1965: }
1966: $request->print($prnmsg);
1.32 ng 1967:
1.257 albertel 1968: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1969: #
1970: # Print out the keyword options line
1971: #
1.41 ng 1972: $request->print(<<KEYWORDS);
1.38 ng 1973: <b>Keyword Options:</b>
1.417 albertel 1974: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.38 ng 1975: <a href="#" onMouseDown="javascript:getSel(); return false"
1976: CLASS="page">Paste Selection to List</a>
1.417 albertel 1977: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 1978: KEYWORDS
1.88 www 1979: #
1980: # Load the other essays for similarity check
1981: #
1.324 albertel 1982: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 1983: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 1984: $apath=&escape($apath);
1.88 www 1985: $apath=~s/\W/\_/gs;
1.426 albertel 1986: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1987: }
1988: }
1.44 ng 1989:
1.441 www 1990: # This is where output for one specific student would start
1.468 albertel 1991: my $add_class = ($counter%2) ? 'LC_grade_show_user_odd_row' : '';
1.441 www 1992: $request->print("\n\n".
1.468 albertel 1993: '<div class="LC_grade_show_user '.$add_class.'">'.
1994: '<div class="LC_grade_user_name">'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</div>'.
1995: '<div class="LC_grade_show_user_body">'."\n");
1.441 www 1996:
1.257 albertel 1997: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 1998: my $mode;
1.257 albertel 1999: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2000: $mode='both';
1.257 albertel 2001: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2002: $mode='text';
1.257 albertel 2003: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2004: $mode='answer';
2005: }
1.329 albertel 2006: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2007: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2008: }
1.144 albertel 2009:
1.257 albertel 2010: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2011: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 2012:
1.44 ng 2013: # Display student info
1.41 ng 2014: $request->print(($counter == 0 ? '' : '<br />'));
1.468 albertel 2015: my $result='<div class="LC_grade_submissions">';
2016:
2017: $result.='<div class="LC_grade_submissions_header">';
2018: $result.= &mt('Submissions');
1.45 ng 2019: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 2020: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2021: if ($env{'form.handgrade'} eq 'no') {
2022: $result.='<span class="LC_grade_check_note">'.
2023: &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)."</span>\n";
2024:
2025: }
2026:
2027:
1.41 ng 2028:
1.118 ng 2029: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2030: my $fullname;
2031: my $col_fullnames = [];
1.257 albertel 2032: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2033: (my $sub_result,$fullname,$col_fullnames)=
2034: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2035: $counter);
2036: $result.=$sub_result;
1.41 ng 2037: }
1.44 ng 2038: $request->print($result."\n");
1.468 albertel 2039: $request->print('</div>'."\n");
1.44 ng 2040: # print student answer/submission
2041: # Options are (1) Handgaded submission only
2042: # (2) Last submission, includes submission that is not handgraded
2043: # (for multi-response type part)
2044: # (3) Last submission plus the parts info
2045: # (4) The whole record for this student
1.257 albertel 2046: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2047: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2048:
2049: my $lastsubonly;
2050:
1.151 albertel 2051: if ($$timestamp eq '') {
1.468 albertel 2052: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
1.151 albertel 2053: } else {
1.468 albertel 2054: $lastsubonly = '<div class="LC_grade_submissions_body"> <b>Date Submitted:</b> '.$$timestamp."\n";
2055:
1.151 albertel 2056: my %seenparts;
1.375 albertel 2057: my @part_response_id = &flatten_responseType($responseType);
2058: foreach my $part (@part_response_id) {
1.393 albertel 2059: next if ($env{'form.lastSub'} eq 'hdgrade'
2060: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2061:
1.375 albertel 2062: my ($partid,$respid) = @{ $part };
1.324 albertel 2063: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2064: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2065: if (exists($seenparts{$partid})) { next; }
2066: $seenparts{$partid}=1;
1.207 albertel 2067: my $submitby='<b>Part:</b> '.$display_part.
2068: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2069: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2070: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2071: '\');" target="_self">'.
1.257 albertel 2072: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2073: $request->print($submitby);
2074: next;
2075: }
2076: my $responsetype = $responseType->{$partid}->{$respid};
2077: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.468 albertel 2078: $lastsubonly.="\n".'<div class="LC_grade_submission_part"><b>Part:</b> '.
1.398 albertel 2079: $display_part.' <span class="LC_internal_info">( ID '.$respid.
2080: ' )</span> '.
1.539 riegler 2081: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2082: next;
2083: }
1.468 albertel 2084: foreach my $submission (@$string) {
2085: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2086: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.468 albertel 2087: my ($ressub,$subval) = split(/:/,$submission,2);
1.151 albertel 2088: # Similarity check
2089: my $similar='';
1.257 albertel 2090: if($env{'form.checkPlag'}){
1.151 albertel 2091: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2092: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2093: if ($osim) {
2094: $osim=int($osim*100.0);
1.426 albertel 2095: my %old_course_desc =
2096: &Apache::lonnet::coursedescription($ocrsid,
2097: {'one_time' => 1});
2098:
2099: $similar="<hr /><h3><span class=\"LC_warning\">".
1.427 albertel 2100: &mt('Essay is [_1]% similar to an essay by [_2] ([_3]:[_4]) in course [_5] (course id [_6]:[_7])',
1.426 albertel 2101: $osim,
2102: &Apache::loncommon::plainname($oname,$odom),
1.427 albertel 2103: $oname,$odom,
1.426 albertel 2104: $old_course_desc{'description'},
1.427 albertel 2105: $old_course_desc{'num'},
1.426 albertel 2106: $old_course_desc{'domain'}).
1.398 albertel 2107: '</span></h3><blockquote><i>'.
1.151 albertel 2108: &keywords_highlight($oessay).
2109: '</i></blockquote><hr />';
2110: }
1.150 albertel 2111: }
1.151 albertel 2112: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2113: if ($env{'form.lastSub'} eq 'lastonly' ||
2114: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2115: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2116: my $display_part=&get_display_part($partid,$symb);
1.468 albertel 2117: $lastsubonly.='<div class="LC_grade_submission_part"><b>Part:</b> '.
1.403 albertel 2118: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1.398 albertel 2119: ' )</span> ';
1.313 banghart 2120: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2121: if (@$files) {
1.544 raeburn 2122: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
1.303 banghart 2123: my $file_counter = 0;
1.313 banghart 2124: foreach my $file (@$files) {
1.468 albertel 2125: $file_counter++;
1.232 albertel 2126: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 2127: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 2128: }
1.236 albertel 2129: $lastsubonly.='<br />';
1.41 ng 2130: }
1.468 albertel 2131: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
1.151 albertel 2132: &cleanRecord($subval,$responsetype,$symb,$partid,
1.555 raeburn 2133: $respid,\%record,$order,undef,$uname,$udom);
1.151 albertel 2134: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2135: $lastsubonly.='</div>';
1.41 ng 2136: }
2137: }
2138: }
1.468 albertel 2139: $lastsubonly.='</div>'."\n";
1.151 albertel 2140: }
2141: $request->print($lastsubonly);
1.468 albertel 2142: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2143: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2144: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2145: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2146: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2147: $env{'request.course.id'},
1.44 ng 2148: $last,'.submission',
2149: 'Apache::grades::keywords_highlight'));
1.41 ng 2150: }
1.120 ng 2151:
1.121 ng 2152: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2153: .$udom.'" />'."\n");
1.44 ng 2154: # return if view submission with no grading option
1.257 albertel 2155: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2156: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2157: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2158: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2159: $toGrade.='</div>'."\n";
1.257 albertel 2160: if (($env{'form.command'} eq 'submission') ||
2161: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2162: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2163: }
1.180 albertel 2164: $request->print($toGrade);
1.41 ng 2165: return;
1.180 albertel 2166: } else {
1.468 albertel 2167: $request->print('</div>'."\n");
1.41 ng 2168: }
1.33 ng 2169:
1.121 ng 2170: # essay grading message center
1.257 albertel 2171: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2172: my $result='<div class="LC_grade_message_center">';
2173:
2174: $result.='<div class="LC_grade_message_center_header">'.
2175: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2176: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2177: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2178: if (scalar(@$col_fullnames) > 0) {
2179: my $lastone = pop(@$col_fullnames);
2180: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2181: }
2182: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2183: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2184: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2185: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2186: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2187: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2188: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2189: '<img src="'.$request->dir_config('lonIconsURL').
2190: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2191: '<br /> ('.
1.468 albertel 2192: &mt('Message will be sent when you click on Save & Next below.').")\n";
2193: $result.='</div></div>';
1.121 ng 2194: $request->print($result);
1.118 ng 2195: }
1.41 ng 2196:
2197: my %seen = ();
2198: my @partlist;
1.129 ng 2199: my @gradePartRespid;
1.375 albertel 2200: my @part_response_id = &flatten_responseType($responseType);
1.468 albertel 2201: $request->print('<div class="LC_grade_assign">'.
2202:
2203: '<div class="LC_grade_assign_header">'.
2204: &mt('Assign Grades').'</div>'.
2205: '<div class="LC_grade_assign_body">');
1.375 albertel 2206: foreach my $part_response_id (@part_response_id) {
2207: my ($partid,$respid) = @{ $part_response_id };
2208: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2209: next if ($seen{$partid} > 0);
1.41 ng 2210: $seen{$partid}++;
1.393 albertel 2211: next if ($$handgrade{$part_resp} ne 'yes'
2212: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2213: push(@partlist,$partid);
2214: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2215: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2216: }
1.468 albertel 2217: $request->print('</div></div>');
2218:
2219: $request->print('<div class="LC_grade_info_links">');
2220: if ($perm{'vgr'}) {
2221: $request->print(
2222: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2223: $uname,$udom,'check'));
2224: }
2225: if ($perm{'opa'}) {
2226: $request->print(
2227: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2228: $uname,$udom,$symb,'check'));
2229: }
2230: $request->print('</div>');
2231:
1.45 ng 2232: $result='<input type="hidden" name="partlist'.$counter.
2233: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2234: $result.='<input type="hidden" name="gradePartRespid'.
2235: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2236: my $ctr = 0;
2237: while ($ctr < scalar(@partlist)) {
2238: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2239: $partlist[$ctr].'" />'."\n";
2240: $ctr++;
2241: }
1.468 albertel 2242: $request->print($result.''."\n");
1.41 ng 2243:
1.441 www 2244: # Done with printing info for one student
2245:
1.468 albertel 2246: $request->print('</div>');#LC_grade_show_user_body
2247: $request->print('</div>');#LC_grade_show_user
1.441 www 2248:
2249:
1.41 ng 2250: # print end of form
2251: if ($counter == $total) {
1.297 www 2252: my $endform='<table border="0"><tr><td>'."\n";
1.485 albertel 2253: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.119 ng 2254: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2255: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2256: my $ntstu ='<select name="NTSTU">'.
2257: '<option>1</option><option>2</option>'.
2258: '<option>3</option><option>5</option>'.
2259: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2260: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2261: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.549 hauer 2262: $endform.=&mt('[quant,_1,student]',$ntstu);
1.485 albertel 2263: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.417 albertel 2264: 'onClick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2265: '<input type="button" value="'.&mt('Next').'" '.
1.417 albertel 2266: 'onClick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.485 albertel 2267: $endform.=&mt('(Next and Previous (student) do not save the scores.)')."\n" ;
1.349 albertel 2268: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2269: "' name='increment' />";
1.485 albertel 2270: $endform.='</td></tr></table></form>';
1.324 albertel 2271: $endform.=&show_grading_menu_form($symb);
1.41 ng 2272: $request->print($endform);
2273: }
2274: return '';
1.38 ng 2275: }
2276:
1.464 albertel 2277: sub check_collaborators {
2278: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2279: my ($result,@col_fullnames);
2280: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2281: foreach my $part (keys(%$handgrade)) {
2282: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2283: '.maxcollaborators',
2284: $symb,$udom,$uname);
2285: next if ($ncol <= 0);
2286: $part =~ s/\_/\./g;
2287: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2288: my (@good_collaborators, @bad_collaborators);
2289: foreach my $possible_collaborator
2290: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2291: $possible_collaborator =~ s/[\$\^\(\)]//g;
2292: next if ($possible_collaborator eq '');
2293: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2294: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2295: next if ($co_name eq $uname && $co_dom eq $udom);
2296: # Doing this grep allows 'fuzzy' specification
2297: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2298: keys(%$classlist));
2299: if (! scalar(@matches)) {
2300: push(@bad_collaborators, $possible_collaborator);
2301: } else {
2302: push(@good_collaborators, @matches);
2303: }
2304: }
2305: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2306: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2307: foreach my $name (@good_collaborators) {
2308: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2309: push(@col_fullnames, $givenn.' '.$lastname);
2310: $result.=$fullname->{$name}.' ';
2311: }
2312: $result.='<br />'."\n";
1.466 albertel 2313: my ($part)=split(/\./,$part);
1.464 albertel 2314: $result.='<input type="hidden" name="collaborator'.$counter.
2315: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2316: "\n";
2317: }
2318: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2319: $result.='<div class="LC_warning">';
1.464 albertel 2320: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2321: $result .= '</div>';
2322: }
2323: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2324: $result .= '<div class="LC_warning">';
1.464 albertel 2325: $result .= &mt('This student has submitted too many '.
2326: 'collaborators. Maximum is [_1].',$ncol);
2327: $result .= '</div>';
2328: }
2329: }
2330: return ($result,$fullname,\@col_fullnames);
2331: }
2332:
1.44 ng 2333: #--- Retrieve the last submission for all the parts
1.38 ng 2334: sub get_last_submission {
1.119 ng 2335: my ($returnhash)=@_;
1.46 ng 2336: my (@string,$timestamp);
1.119 ng 2337: if ($$returnhash{'version'}) {
1.46 ng 2338: my %lasthash=();
2339: my ($version);
1.119 ng 2340: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2341: foreach my $key (sort(split(/\:/,
2342: $$returnhash{$version.':keys'}))) {
2343: $lasthash{$key}=$$returnhash{$version.':'.$key};
2344: $timestamp =
1.545 raeburn 2345: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2346: }
2347: }
1.397 albertel 2348: foreach my $key (keys(%lasthash)) {
2349: next if ($key !~ /\.submission$/);
2350:
2351: my ($partid,$foo) = split(/submission$/,$key);
2352: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2353: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2354: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2355: }
2356: }
1.397 albertel 2357: if (!@string) {
2358: $string[0] =
1.539 riegler 2359: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2360: }
2361: return (\@string,\$timestamp);
1.38 ng 2362: }
1.35 ng 2363:
1.44 ng 2364: #--- High light keywords, with style choosen by user.
1.38 ng 2365: sub keywords_highlight {
1.44 ng 2366: my $string = shift;
1.257 albertel 2367: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2368: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2369: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2370: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2371: foreach my $keyword (@keylist) {
2372: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2373: }
2374: return $string;
1.38 ng 2375: }
1.36 ng 2376:
1.44 ng 2377: #--- Called from submission routine
1.38 ng 2378: sub processHandGrade {
1.41 ng 2379: my ($request) = shift;
1.324 albertel 2380: my $symb = &get_symb($request);
2381: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2382: my $button = $env{'form.gradeOpt'};
2383: my $ngrade = $env{'form.NCT'};
2384: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2385: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2386: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2387:
1.44 ng 2388: if ($button eq 'Save & Next') {
2389: my $ctr = 0;
2390: while ($ctr < $ngrade) {
1.257 albertel 2391: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2392: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2393: if ($errorflag eq 'no_score') {
2394: $ctr++;
2395: next;
2396: }
1.104 albertel 2397: if ($errorflag eq 'not_allowed') {
1.398 albertel 2398: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2399: $ctr++;
2400: next;
2401: }
1.257 albertel 2402: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2403: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2404: my $restitle = &Apache::lonnet::gettitle($symb);
2405: my ($feedurl,$showsymb) =
2406: &get_feedurl_and_symb($symb,$uname,$udom);
2407: my $messagetail;
1.62 albertel 2408: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2409: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2410: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2411: $subject.=' ['.$restitle.']';
1.44 ng 2412: my (@msgnum) = split(/,/,$includemsg);
2413: foreach (@msgnum) {
1.257 albertel 2414: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2415: }
1.80 ng 2416: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2417: if ($env{'form.withgrades'.$ctr}) {
2418: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2419: $messagetail = " for <a href=\"".
1.418 albertel 2420: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2421: }
2422: $msgstatus =
2423: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2424: $message.$messagetail,
1.418 albertel 2425: undef,$feedurl,undef,
1.386 raeburn 2426: undef,undef,$showsymb,
2427: $restitle);
2428: $request->print('<br />'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
1.296 www 2429: $msgstatus);
1.44 ng 2430: }
1.257 albertel 2431: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2432: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2433: foreach my $collabstr (@collabstrs) {
2434: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2435: foreach my $collaborator (@collaborators) {
1.150 albertel 2436: my ($errorflag,$pts,$wgt) =
1.324 albertel 2437: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2438: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2439: if ($errorflag eq 'not_allowed') {
1.362 albertel 2440: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2441: next;
1.418 albertel 2442: } elsif ($message ne '') {
2443: my ($baseurl,$showsymb) =
2444: &get_feedurl_and_symb($symb,$collaborator,
2445: $udom);
2446: if ($env{'form.withgrades'.$ctr}) {
2447: $messagetail = " for <a href=\"".
1.386 raeburn 2448: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2449: }
1.418 albertel 2450: $msgstatus =
2451: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2452: }
1.44 ng 2453: }
2454: }
2455: }
2456: $ctr++;
2457: }
2458: }
2459:
1.257 albertel 2460: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2461: # Keywords sorted in alphabatical order
1.257 albertel 2462: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2463: my %keyhash = ();
1.257 albertel 2464: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2465: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2466: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2467: $env{'form.keywords'} = join(' ',@keywords);
2468: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2469: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2470: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2471: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2472: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2473:
2474: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2475: # New messages are saved in env for the next student.
1.119 ng 2476: # All messages are saved in nohist_handgrade.db
2477: my ($ctr,$idx) = (1,1);
1.257 albertel 2478: while ($ctr <= $env{'form.savemsgN'}) {
2479: if ($env{'form.savemsg'.$ctr} ne '') {
2480: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2481: $idx++;
2482: }
2483: $ctr++;
1.41 ng 2484: }
1.119 ng 2485: $ctr = 0;
2486: while ($ctr < $ngrade) {
1.257 albertel 2487: if ($env{'form.newmsg'.$ctr} ne '') {
2488: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2489: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2490: $idx++;
2491: }
2492: $ctr++;
1.41 ng 2493: }
1.257 albertel 2494: $env{'form.savemsgN'} = --$idx;
2495: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2496: my $putresult = &Apache::lonnet::put
1.301 albertel 2497: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2498: }
1.44 ng 2499: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2500: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2501: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2502: my ($ctr,$total) = (0,0);
2503: while ($ctr < $ngrade) {
1.257 albertel 2504: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2505: $ctr++;
2506: }
1.257 albertel 2507: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2508: $ctr = 0;
2509: while ($ctr < $total) {
1.257 albertel 2510: my $processUser = $env{'form.unamedom'.$ctr};
2511: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2512: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2513: &submission($request,$ctr,$total-1);
1.41 ng 2514: $ctr++;
2515: }
2516: return '';
2517: }
1.36 ng 2518:
1.121 ng 2519: # Go directly to grade student - from submission or link from chart page
1.120 ng 2520: if ($button eq 'Grade Student') {
1.324 albertel 2521: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2522: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2523: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2524: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2525: &submission($request,0,0);
2526: return '';
2527: }
2528:
1.44 ng 2529: # Get the next/previous one or group of students
1.257 albertel 2530: my $firststu = $env{'form.unamedom0'};
2531: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2532: my $ctr = 2;
1.41 ng 2533: while ($laststu eq '') {
1.257 albertel 2534: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2535: $ctr++;
2536: $laststu = $firststu if ($ctr > $ngrade);
2537: }
1.44 ng 2538:
1.41 ng 2539: my (@parsedlist,@nextlist);
2540: my ($nextflg) = 0;
1.524 raeburn 2541: foreach my $item (sort
1.294 albertel 2542: {
2543: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2544: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2545: }
2546: return $a cmp $b;
2547: } (keys(%$fullname))) {
1.41 ng 2548: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2549: push(@parsedlist,$item);
1.41 ng 2550: }
1.524 raeburn 2551: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2552: if ($button eq 'Previous') {
1.524 raeburn 2553: last if ($item eq $firststu);
2554: push(@parsedlist,$item);
1.41 ng 2555: }
2556: }
2557: $ctr = 0;
2558: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2559: my ($partlist) = &response_type($symb);
1.41 ng 2560: foreach my $student (@parsedlist) {
1.257 albertel 2561: my $submitonly=$env{'form.submitonly'};
1.41 ng 2562: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2563:
2564: if ($submitonly eq 'queued') {
2565: my %queue_status =
2566: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2567: $udom,$uname);
2568: next if (!defined($queue_status{'gradingqueue'}));
2569: }
2570:
1.156 albertel 2571: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2572: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2573: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2574: my $submitted = 0;
1.248 albertel 2575: my $ungraded = 0;
2576: my $incorrect = 0;
1.524 raeburn 2577: foreach my $item (keys(%status)) {
2578: $submitted = 1 if ($status{$item} ne 'nothing');
2579: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2580: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2581: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2582: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2583: $submitted = 0;
2584: }
1.41 ng 2585: }
1.156 albertel 2586: next if (!$submitted && ($submitonly eq 'yes' ||
2587: $submitonly eq 'incorrect' ||
2588: $submitonly eq 'graded'));
1.248 albertel 2589: next if (!$ungraded && ($submitonly eq 'graded'));
2590: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2591: }
1.524 raeburn 2592: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2593: last if ($ctr == $ntstu);
1.41 ng 2594: $ctr++;
2595: }
1.36 ng 2596:
1.41 ng 2597: $ctr = 0;
2598: my $total = scalar(@nextlist)-1;
1.39 ng 2599:
1.524 raeburn 2600: foreach (sort(@nextlist)) {
1.41 ng 2601: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2602: $env{'form.student'} = $uname;
2603: $env{'form.userdom'} = $udom;
2604: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2605: &submission($request,$ctr,$total);
2606: $ctr++;
2607: }
2608: if ($total < 0) {
1.485 albertel 2609: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2610: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2611: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2612: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2613: $request->print($the_end);
2614: }
2615: return '';
1.38 ng 2616: }
1.36 ng 2617:
1.44 ng 2618: #---- Save the score and award for each student, if changed
1.38 ng 2619: sub saveHandGrade {
1.324 albertel 2620: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2621: my @version_parts;
1.104 albertel 2622: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2623: $env{'request.course.id'});
1.104 albertel 2624: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2625: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2626: my @parts_graded;
1.77 ng 2627: my %newrecord = ();
2628: my ($pts,$wgt) = ('','');
1.269 raeburn 2629: my %aggregate = ();
2630: my $aggregateflag = 0;
1.301 albertel 2631: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2632: foreach my $new_part (@parts) {
1.337 banghart 2633: #collaborator ($submi may vary for different parts
1.259 banghart 2634: if ($submitter && $new_part ne $part) { next; }
2635: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2636: if ($dropMenu eq 'excused') {
1.259 banghart 2637: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2638: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2639: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2640: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2641: }
1.364 banghart 2642: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2643: }
1.125 ng 2644: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2645: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2646: foreach my $key (keys(%record)) {
1.259 banghart 2647: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2648: }
1.259 banghart 2649: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2650: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2651: my $totaltries = $record{'resource.'.$part.'.tries'};
2652:
2653: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2654: [$new_part]);
2655: my $aggtries =$totaltries;
1.269 raeburn 2656: if ($last_resets{$new_part}) {
1.270 albertel 2657: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2658: $new_part);
1.269 raeburn 2659: }
1.270 albertel 2660:
2661: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2662: if ($aggtries > 0) {
1.327 albertel 2663: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2664: $aggregateflag = 1;
2665: }
1.125 ng 2666: } elsif ($dropMenu eq '') {
1.259 banghart 2667: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2668: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2669: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2670: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2671: next;
2672: }
1.259 banghart 2673: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2674: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2675: my $partial= $pts/$wgt;
1.259 banghart 2676: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2677: #do not update score for part if not changed.
1.346 banghart 2678: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2679: next;
1.251 banghart 2680: } else {
1.524 raeburn 2681: push(@parts_graded,$new_part);
1.153 albertel 2682: }
1.259 banghart 2683: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2684: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2685: }
1.259 banghart 2686: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2687: if ($partial == 0) {
1.153 albertel 2688: if ($record{$reckey} ne 'incorrect_by_override') {
2689: $newrecord{$reckey} = 'incorrect_by_override';
2690: }
1.41 ng 2691: } else {
1.153 albertel 2692: if ($record{$reckey} ne 'correct_by_override') {
2693: $newrecord{$reckey} = 'correct_by_override';
2694: }
2695: }
2696: if ($submitter &&
1.259 banghart 2697: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2698: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2699: }
1.259 banghart 2700: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2701: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2702: }
1.259 banghart 2703: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2704: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2705: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2706: $dropMenu eq 'reset status')
2707: {
1.524 raeburn 2708: push(@version_parts,$new_part);
1.259 banghart 2709: }
1.41 ng 2710: }
1.301 albertel 2711: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2712: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2713:
1.344 albertel 2714: if (%newrecord) {
2715: if (@version_parts) {
1.364 banghart 2716: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2717: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2718: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2719: foreach my $new_part (@version_parts) {
2720: &handback_files($request,$symb,$stuname,$domain,$newflg,
2721: $new_part,\%newrecord);
2722: }
1.259 banghart 2723: }
1.44 ng 2724: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2725: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2726: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2727: $cdom,$cnum,$domain,$stuname);
1.41 ng 2728: }
1.269 raeburn 2729: if ($aggregateflag) {
2730: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2731: $cdom,$cnum);
1.269 raeburn 2732: }
1.301 albertel 2733: return ('',$pts,$wgt);
1.36 ng 2734: }
1.322 albertel 2735:
1.380 albertel 2736: sub check_and_remove_from_queue {
2737: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2738: my @ungraded_parts;
2739: foreach my $part (@{$parts}) {
2740: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2741: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2742: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2743: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2744: ) {
2745: push(@ungraded_parts, $part);
2746: }
2747: }
2748: if ( !@ungraded_parts ) {
2749: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2750: $cnum,$domain,$stuname);
2751: }
2752: }
2753:
1.337 banghart 2754: sub handback_files {
2755: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2756: my $portfolio_root = '/userfiles/portfolio';
1.359 www 2757: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2758:
2759: my @part_response_id = &flatten_responseType($responseType);
2760: foreach my $part_response_id (@part_response_id) {
2761: my ($part_id,$resp_id) = @{ $part_response_id };
2762: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2763: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2764: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2765: my $file_counter = 1;
1.367 albertel 2766: my $file_msg;
1.337 banghart 2767: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2768: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2769: my ($directory,$answer_file) =
2770: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2771: my ($answer_name,$answer_ver,$answer_ext) =
2772: &file_name_version_ext($answer_file);
1.355 banghart 2773: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2774: my $getpropath = 1;
2775: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2776: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2777: # fix file name
2778: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2779: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2780: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2781: $save_file_name);
1.337 banghart 2782: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2783: $request->print('<br /><span class="LC_error">'.
2784: &mt('An error occurred ([_1]) while trying to upload [_2].',
2785: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2786: '</span>');
1.356 banghart 2787: } else {
1.360 banghart 2788: # mark the file as read only
2789: my @files = ($save_file_name);
1.372 albertel 2790: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2791: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2792: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2793: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2794: }
2795: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2796: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2797:
1.337 banghart 2798: }
2799: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2800: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2801: $file_counter++;
2802: }
1.367 albertel 2803: my $subject = "File Handed Back by Instructor ";
2804: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2805: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2806: $message .= ' The returned file(s) are named: '. $file_msg;
2807: $message .= " and can be found in your portfolio space.";
1.418 albertel 2808: my ($feedurl,$showsymb) =
2809: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2810: my $restitle = &Apache::lonnet::gettitle($symb);
2811: my $msgstatus =
2812: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2813: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2814: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2815: }
2816: }
1.338 banghart 2817: return;
1.337 banghart 2818: }
2819:
1.418 albertel 2820: sub get_feedurl_and_symb {
2821: my ($symb,$uname,$udom) = @_;
2822: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2823: $url = &Apache::lonnet::clutter($url);
2824: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2825: $symb,$udom,$uname);
2826: if ($encrypturl =~ /^yes$/i) {
2827: &Apache::lonenc::encrypted(\$url,1);
2828: &Apache::lonenc::encrypted(\$symb,1);
2829: }
2830: return ($url,$symb);
2831: }
2832:
1.313 banghart 2833: sub get_submitted_files {
2834: my ($udom,$uname,$partid,$respid,$record) = @_;
2835: my @files;
2836: if ($$record{"resource.$partid.$respid.portfiles"}) {
2837: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2838: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2839: push(@files,$file_url.$file);
2840: }
2841: }
2842: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2843: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2844: }
2845: return (\@files);
2846: }
1.322 albertel 2847:
1.269 raeburn 2848: # ----------- Provides number of tries since last reset.
2849: sub get_num_tries {
2850: my ($record,$last_reset,$part) = @_;
2851: my $timestamp = '';
2852: my $num_tries = 0;
2853: if ($$record{'version'}) {
2854: for (my $version=$$record{'version'};$version>=1;$version--) {
2855: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2856: $timestamp = $$record{$version.':timestamp'};
2857: if ($timestamp > $last_reset) {
2858: $num_tries ++;
2859: } else {
2860: last;
2861: }
2862: }
2863: }
2864: }
2865: return $num_tries;
2866: }
2867:
2868: # ----------- Determine decrements required in aggregate totals
2869: sub decrement_aggs {
2870: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2871: my %decrement = (
2872: attempts => 0,
2873: users => 0,
2874: correct => 0
2875: );
2876: $decrement{'attempts'} = $aggtries;
2877: if ($solvedstatus =~ /^correct/) {
2878: $decrement{'correct'} = 1;
2879: }
2880: if ($aggtries == $totaltries) {
2881: $decrement{'users'} = 1;
2882: }
1.524 raeburn 2883: foreach my $type (keys(%decrement)) {
1.269 raeburn 2884: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2885: }
2886: return;
2887: }
2888:
2889: # ----------- Determine timestamps for last reset of aggregate totals for parts
2890: sub get_last_resets {
1.270 albertel 2891: my ($symb,$courseid,$partids) =@_;
2892: my %last_resets;
1.269 raeburn 2893: my $cdom = $env{'course.'.$courseid.'.domain'};
2894: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2895: my @keys;
2896: foreach my $part (@{$partids}) {
2897: push(@keys,"$symb\0$part\0resettime");
2898: }
2899: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2900: $cdom,$cname);
2901: foreach my $part (@{$partids}) {
2902: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2903: }
1.270 albertel 2904: return %last_resets;
1.269 raeburn 2905: }
2906:
1.251 banghart 2907: # ----------- Handles creating versions for portfolio files as answers
2908: sub version_portfiles {
1.343 banghart 2909: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2910: my $version_parts = join('|',@$v_flag);
1.343 banghart 2911: my @returned_keys;
1.255 banghart 2912: my $parts = join('|', @$parts_graded);
1.517 raeburn 2913: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 2914: foreach my $key (keys(%$record)) {
1.259 banghart 2915: my $new_portfiles;
1.263 banghart 2916: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2917: my @versioned_portfiles;
1.367 albertel 2918: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2919: foreach my $file (@portfiles) {
1.306 banghart 2920: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2921: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2922: my ($answer_name,$answer_ver,$answer_ext) =
2923: &file_name_version_ext($answer_file);
1.517 raeburn 2924: my $getpropath = 1;
2925: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 2926: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2927: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2928: if ($new_answer ne 'problem getting file') {
1.342 banghart 2929: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2930: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2931: [$directory.$new_answer],
1.306 banghart 2932: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2933: }
1.252 banghart 2934: }
1.343 banghart 2935: $$record{$key} = join(',',@versioned_portfiles);
2936: push(@returned_keys,$key);
1.251 banghart 2937: }
2938: }
1.343 banghart 2939: return (@returned_keys);
1.305 banghart 2940: }
2941:
1.307 banghart 2942: sub get_next_version {
1.341 banghart 2943: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2944: my $version;
2945: foreach my $row (@$dir_list) {
2946: my ($file) = split(/\&/,$row,2);
2947: my ($file_name,$file_version,$file_ext) =
2948: &file_name_version_ext($file);
2949: if (($file_name eq $answer_name) &&
2950: ($file_ext eq $answer_ext)) {
2951: # gets here if filename and extension match, regardless of version
2952: if ($file_version ne '') {
2953: # a versioned file is found so save it for later
2954: if ($file_version > $version) {
2955: $version = $file_version;
2956: }
2957: }
2958: }
2959: }
2960: $version ++;
2961: return($version);
2962: }
2963:
1.305 banghart 2964: sub version_selected_portfile {
1.306 banghart 2965: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2966: my ($answer_name,$answer_ver,$answer_ext) =
2967: &file_name_version_ext($file_name);
2968: my $new_answer;
2969: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2970: if($env{'form.copy'} eq '-1') {
2971: $new_answer = 'problem getting file';
2972: } else {
2973: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2974: my $copy_result = &Apache::lonnet::finishuserfileupload(
2975: $stu_name,$domain,'copy',
2976: '/portfolio'.$directory.$new_answer);
2977: }
2978: return ($new_answer);
1.251 banghart 2979: }
2980:
1.304 albertel 2981: sub file_name_version_ext {
2982: my ($file)=@_;
2983: my @file_parts = split(/\./, $file);
2984: my ($name,$version,$ext);
2985: if (@file_parts > 1) {
2986: $ext=pop(@file_parts);
2987: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2988: $version=pop(@file_parts);
2989: }
2990: $name=join('.',@file_parts);
2991: } else {
2992: $name=join('.',@file_parts);
2993: }
2994: return($name,$version,$ext);
2995: }
2996:
1.44 ng 2997: #--------------------------------------------------------------------------------------
2998: #
2999: #-------------------------- Next few routines handles grading by section or whole class
3000: #
3001: #--- Javascript to handle grading by section or whole class
1.42 ng 3002: sub viewgrades_js {
3003: my ($request) = shift;
3004:
1.539 riegler 3005: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3006: $request->print(<<VIEWJAVASCRIPT);
3007: <script type="text/javascript" language="javascript">
1.45 ng 3008: function writePoint(partid,weight,point) {
1.125 ng 3009: var radioButton = document.classgrade["RADVAL_"+partid];
3010: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3011: if (point == "textval") {
1.125 ng 3012: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3013: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3014: alert("$alertmsg"+parseFloat(point));
1.42 ng 3015: var resetbox = false;
3016: for (var i=0; i<radioButton.length; i++) {
3017: if (radioButton[i].checked) {
3018: textbox.value = i;
3019: resetbox = true;
3020: }
3021: }
3022: if (!resetbox) {
3023: textbox.value = "";
3024: }
3025: return;
3026: }
1.109 matthew 3027: if (parseFloat(point) > parseFloat(weight)) {
3028: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3029: ") greater than the weight for the part. Accept?");
3030: if (resp == false) {
3031: textbox.value = "";
3032: return;
3033: }
3034: }
1.42 ng 3035: for (var i=0; i<radioButton.length; i++) {
3036: radioButton[i].checked=false;
1.109 matthew 3037: if (parseFloat(point) == i) {
1.42 ng 3038: radioButton[i].checked=true;
3039: }
3040: }
1.41 ng 3041:
1.42 ng 3042: } else {
1.125 ng 3043: textbox.value = parseFloat(point);
1.42 ng 3044: }
1.41 ng 3045: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3046: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3047: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3048: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3049: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3050: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3051: if (saveval != "correct") {
3052: scorename.value = point;
1.43 ng 3053: if (selname[0].selected != true) {
3054: selname[0].selected = true;
3055: }
1.42 ng 3056: }
3057: }
1.125 ng 3058: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3059: }
3060:
3061: function writeRadText(partid,weight) {
1.125 ng 3062: var selval = document.classgrade["SELVAL_"+partid];
3063: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3064: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3065: var textbox = document.classgrade["TEXTVAL_"+partid];
3066: if (selval[1].selected || selval[2].selected) {
1.42 ng 3067: for (var i=0; i<radioButton.length; i++) {
3068: radioButton[i].checked=false;
3069:
3070: }
3071: textbox.value = "";
3072:
3073: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3074: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3075: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3076: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3077: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3078: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3079: if ((saveval != "correct") || override) {
1.42 ng 3080: scorename.value = "";
1.125 ng 3081: if (selval[1].selected) {
3082: selname[1].selected = true;
3083: } else {
3084: selname[2].selected = true;
3085: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3086: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3087: }
1.42 ng 3088: }
3089: }
1.43 ng 3090: } else {
3091: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3092: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3093: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3094: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3095: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3096: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3097: if ((saveval != "correct") || override) {
1.125 ng 3098: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3099: selname[0].selected = true;
3100: }
3101: }
3102: }
1.42 ng 3103: }
3104:
3105: function changeSelect(partid,user) {
1.125 ng 3106: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3107: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3108: var point = textbox.value;
1.125 ng 3109: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3110:
1.109 matthew 3111: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3112: alert("$alertmsg"+parseFloat(point));
1.44 ng 3113: textbox.value = "";
3114: return;
3115: }
1.109 matthew 3116: if (parseFloat(point) > parseFloat(weight)) {
3117: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3118: ") greater than the weight of the part. Accept?");
3119: if (resp == false) {
3120: textbox.value = "";
3121: return;
3122: }
3123: }
1.42 ng 3124: selval[0].selected = true;
3125: }
3126:
3127: function changeOneScore(partid,user) {
1.125 ng 3128: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3129: if (selval[1].selected || selval[2].selected) {
3130: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3131: if (selval[2].selected) {
3132: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3133: }
1.269 raeburn 3134: }
1.42 ng 3135: }
3136:
3137: function resetEntry(numpart) {
3138: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3139: var partid = document.classgrade["partid_"+ctpart].value;
3140: var radioButton = document.classgrade["RADVAL_"+partid];
3141: var textbox = document.classgrade["TEXTVAL_"+partid];
3142: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3143: for (var i=0; i<radioButton.length; i++) {
3144: radioButton[i].checked=false;
3145:
3146: }
3147: textbox.value = "";
3148: selval[0].selected = true;
3149:
3150: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3151: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3152: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3153: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3154: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3155: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3156: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3157: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3158: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3159: if (saveselval == "excused") {
1.43 ng 3160: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3161: } else {
1.43 ng 3162: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3163: }
3164: }
1.41 ng 3165: }
1.42 ng 3166: }
3167:
1.41 ng 3168: </script>
3169: VIEWJAVASCRIPT
1.42 ng 3170: }
3171:
1.44 ng 3172: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3173: sub viewgrades {
3174: my ($request) = shift;
3175: &viewgrades_js($request);
1.41 ng 3176:
1.324 albertel 3177: my ($symb) = &get_symb($request);
1.168 albertel 3178: #need to make sure we have the correct data for later EXT calls,
3179: #thus invalidate the cache
3180: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3181: $env{'course.'.$env{'request.course.id'}.'.num'},
3182: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3183: &Apache::lonnet::clear_EXT_cache_status();
3184:
1.398 albertel 3185: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3186: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3187:
3188: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3189: $result.=&jscriptNform($symb);
1.41 ng 3190:
1.44 ng 3191: #beginning of class grading form
1.442 banghart 3192: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3193: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3194: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3195: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3196: &build_section_inputs().
1.257 albertel 3197: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3198: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3199: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3200:
1.126 ng 3201: my $sectionClass;
1.430 banghart 3202: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.257 albertel 3203: if ($env{'form.section'} eq 'all') {
1.539 riegler 3204: $sectionClass=&mt('Class');
1.257 albertel 3205: } elsif ($env{'form.section'} eq 'none') {
1.539 riegler 3206: $sectionClass=&mt('Students in no Section');
1.52 albertel 3207: } else {
1.539 riegler 3208: $sectionClass=&mt('Students in Section(s) [_1]');
1.52 albertel 3209: }
1.485 albertel 3210: $result.=
3211: '<h3>'.
1.539 riegler 3212: &mt("Assign Common Grade to [_1]",$sectionClass,$section_display).'</h3>';
1.474 albertel 3213: $result.= &Apache::loncommon::start_data_table();
1.44 ng 3214: #radio buttons/text box for assigning points for a section or class.
3215: #handles different parts of a problem
1.375 albertel 3216: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 3217: my %weight = ();
3218: my $ctsparts = 0;
1.45 ng 3219: my %seen = ();
1.375 albertel 3220: my @part_response_id = &flatten_responseType($responseType);
3221: foreach my $part_response_id (@part_response_id) {
3222: my ($partid,$respid) = @{ $part_response_id };
3223: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3224: next if $seen{$partid};
3225: $seen{$partid}++;
1.375 albertel 3226: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3227: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3228: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3229:
1.324 albertel 3230: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3231: my $radio.='<table border="0"><tr>';
1.41 ng 3232: my $ctr = 0;
1.42 ng 3233: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3234: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3235: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3236: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3237: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3238: $ctr++;
3239: }
1.485 albertel 3240: $radio.='</tr></table>';
3241: my $line = '<input type="text" name="TEXTVAL_'.
1.54 albertel 3242: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3243: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3244: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3245: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3246: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3247: $weight{$partid}.')"> '.
1.401 albertel 3248: '<option selected="selected"> </option>'.
1.485 albertel 3249: '<option value="excused">'.&mt('excused').'</option>'.
3250: '<option value="reset status">'.&mt('reset status').'</option>'.
3251: '</select></td>'.
3252: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3253: $line.='<input type="hidden" name="partid_'.
3254: $ctsparts.'" value="'.$partid.'" />'."\n";
3255: $line.='<input type="hidden" name="weight_'.
3256: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3257:
3258: $result.=
3259: &Apache::loncommon::start_data_table_row()."\n".
1.539 riegler 3260: '<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 3261: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3262: $ctsparts++;
1.41 ng 3263: }
1.474 albertel 3264: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3265: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3266: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.474 albertel 3267: 'onClick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3268:
1.44 ng 3269: #table listing all the students in a section/class
3270: #header of table
1.539 riegler 3271: $result.= '<h3>'.&mt('Assign Grade to Specific Students in ').$sectionClass,
3272: $section_display.'</h3>';
1.474 albertel 3273: $result.= &Apache::loncommon::start_data_table().
3274: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 3275: '<th>'.&mt('No.').'</th>'.
1.474 albertel 3276: '<th>'.&nameUserString('header')."</th>\n";
1.324 albertel 3277: my (@parts) = sort(&getpartlist($symb));
3278: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3279: my @partids = ();
1.41 ng 3280: foreach my $part (@parts) {
3281: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3282: my $narrowtext = &mt('Tries');
3283: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3284: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3285: my ($partid) = &split_part_type($part);
1.524 raeburn 3286: push(@partids,$partid);
1.324 albertel 3287: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3288: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3289: $result.='<th>'.
3290: &mt('Score Part: [_1]<br /> (weight = [_2])',
3291: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3292: next;
1.485 albertel 3293:
1.207 albertel 3294: } else {
1.485 albertel 3295: if ($display =~ /Problem Status/) {
3296: my $grade_status_mt = &mt('Grade Status');
3297: $display =~ s{Problem Status}{$grade_status_mt<br />};
3298: }
3299: my $part_mt = &mt('Part:');
3300: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3301: }
1.485 albertel 3302:
1.474 albertel 3303: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3304: }
1.474 albertel 3305: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3306:
1.270 albertel 3307: my %last_resets =
3308: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3309:
1.41 ng 3310: #get info for each student
1.44 ng 3311: #list all the students - with points and grade status
1.257 albertel 3312: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3313: my $ctr = 0;
1.294 albertel 3314: foreach (sort
3315: {
3316: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3317: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3318: }
3319: return $a cmp $b;
3320: } (keys(%$fullname))) {
1.126 ng 3321: $ctr++;
1.324 albertel 3322: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3323: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3324: }
1.474 albertel 3325: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3326: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3327: $result.='<input type="button" value="'.&mt('Save').'" '.
1.417 albertel 3328: 'onClick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3329: if (scalar(%$fullname) eq 0) {
3330: my $colspan=3+scalar(@parts);
1.433 banghart 3331: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3332: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3333: $result='<span class="LC_warning">'.
1.485 albertel 3334: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3335: $section_display, $stu_status).
1.433 banghart 3336: '</span>';
1.96 albertel 3337: }
1.324 albertel 3338: $result.=&show_grading_menu_form($symb);
1.41 ng 3339: return $result;
3340: }
3341:
1.44 ng 3342: #--- call by previous routine to display each student
1.41 ng 3343: sub viewstudentgrade {
1.324 albertel 3344: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3345: my ($uname,$udom) = split(/:/,$student);
3346: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3347: my %aggregates = ();
1.474 albertel 3348: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3349: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3350: "\n".$ctr.' </td><td> '.
1.44 ng 3351: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3352: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3353: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3354: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3355: foreach my $apart (@$parts) {
3356: my ($part,$type) = &split_part_type($apart);
1.41 ng 3357: my $score=$record{"resource.$part.$type"};
1.276 albertel 3358: $result.='<td align="center">';
1.269 raeburn 3359: my ($aggtries,$totaltries);
3360: unless (exists($aggregates{$part})) {
1.270 albertel 3361: $totaltries = $record{'resource.'.$part.'.tries'};
3362:
3363: $aggtries = $totaltries;
1.269 raeburn 3364: if ($$last_resets{$part}) {
1.270 albertel 3365: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3366: $part);
3367: }
1.269 raeburn 3368: $result.='<input type="hidden" name="'.
3369: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3370: $result.='<input type="hidden" name="'.
3371: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3372: $aggregates{$part} = 1;
3373: }
1.41 ng 3374: if ($type eq 'awarded') {
1.320 albertel 3375: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3376: $result.='<input type="hidden" name="'.
1.89 albertel 3377: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3378: $result.='<input type="text" name="'.
1.89 albertel 3379: 'GD_'.$student.'_'.$part.'_awarded" '.
3380: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3381: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3382: } elsif ($type eq 'solved') {
3383: my ($status,$foo)=split(/_/,$score,2);
3384: $status = 'nothing' if ($status eq '');
1.89 albertel 3385: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3386: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3387: $result.=' <select name="'.
1.89 albertel 3388: 'GD_'.$student.'_'.$part.'_solved" '.
3389: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3390: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3391: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3392: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3393: $result.="</select> </td>\n";
1.122 ng 3394: } else {
3395: $result.='<input type="hidden" name="'.
3396: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3397: "\n";
1.233 albertel 3398: $result.='<input type="text" name="'.
1.122 ng 3399: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3400: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3401: }
3402: }
1.474 albertel 3403: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3404: return $result;
1.38 ng 3405: }
3406:
1.44 ng 3407: #--- change scores for all the students in a section/class
3408: # record does not get update if unchanged
1.38 ng 3409: sub editgrades {
1.41 ng 3410: my ($request) = @_;
3411:
1.324 albertel 3412: my $symb=&get_symb($request);
1.433 banghart 3413: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3414: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3415: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3416: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3417:
1.477 albertel 3418: my $result= &Apache::loncommon::start_data_table().
3419: &Apache::loncommon::start_data_table_header_row().
3420: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3421: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3422: my %scoreptr = (
3423: 'correct' =>'correct_by_override',
3424: 'incorrect'=>'incorrect_by_override',
3425: 'excused' =>'excused',
3426: 'ungraded' =>'ungraded_attempted',
3427: 'nothing' => '',
3428: );
1.257 albertel 3429: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3430:
1.44 ng 3431: my (@partid);
3432: my %weight = ();
1.54 albertel 3433: my %columns = ();
1.44 ng 3434: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3435:
1.324 albertel 3436: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3437: my $header;
1.257 albertel 3438: while ($ctr < $env{'form.totalparts'}) {
3439: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3440: push(@partid,$partid);
1.257 albertel 3441: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3442: $ctr++;
1.54 albertel 3443: }
1.324 albertel 3444: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3445: foreach my $partid (@partid) {
1.478 albertel 3446: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3447: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3448: $columns{$partid}=2;
3449: foreach my $stores (@parts) {
3450: my ($part,$type) = &split_part_type($stores);
3451: if ($part !~ m/^\Q$partid\E/) { next;}
3452: if ($type eq 'awarded' || $type eq 'solved') { next; }
3453: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3454: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3455: my $narrowtext = &mt('Tries');
3456: $display =~ s/Number of Attempts/$narrowtext/;
3457: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3458: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3459: $columns{$partid}+=2;
3460: }
3461: }
3462: foreach my $partid (@partid) {
1.324 albertel 3463: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3464: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3465: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3466: '</th>';
1.54 albertel 3467:
1.44 ng 3468: }
1.477 albertel 3469: $result .= &Apache::loncommon::end_data_table_header_row().
3470: &Apache::loncommon::start_data_table_header_row().
3471: $header.
3472: &Apache::loncommon::end_data_table_header_row();
3473: my @noupdate;
1.126 ng 3474: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3475: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3476: my $line;
1.257 albertel 3477: my $user = $env{'form.ctr'.$i};
1.281 albertel 3478: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3479: my %newrecord;
3480: my $updateflag = 0;
1.281 albertel 3481: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3482: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3483: if (!&canmodify($usec)) {
1.126 ng 3484: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3485: push(@noupdate,
1.478 albertel 3486: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3487: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3488: next;
3489: }
1.269 raeburn 3490: my %aggregate = ();
3491: my $aggregateflag = 0;
1.281 albertel 3492: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3493: foreach (@partid) {
1.257 albertel 3494: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3495: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3496: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3497: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3498: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3499: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3500: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3501: my $score;
3502: if ($partial eq '') {
1.257 albertel 3503: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3504: } elsif ($partial > 0) {
3505: $score = 'correct_by_override';
3506: } elsif ($partial == 0) {
3507: $score = 'incorrect_by_override';
3508: }
1.257 albertel 3509: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3510: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3511:
1.292 albertel 3512: $newrecord{'resource.'.$_.'.regrader'}=
3513: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3514: if ($dropMenu eq 'reset status' &&
3515: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3516: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3517: $newrecord{'resource.'.$_.'.solved'} = '';
3518: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3519: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3520: $updateflag = 1;
1.269 raeburn 3521: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3522: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3523: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3524: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3525: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3526: $aggregateflag = 1;
3527: }
1.139 albertel 3528: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3529: $updateflag = 1;
3530: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3531: $newrecord{'resource.'.$_.'.solved'} = $score;
3532: $rec_update++;
1.125 ng 3533: }
3534:
1.93 albertel 3535: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3536: '<td align="center">'.$awarded.
3537: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3538:
1.54 albertel 3539:
3540: my $partid=$_;
3541: foreach my $stores (@parts) {
3542: my ($part,$type) = &split_part_type($stores);
3543: if ($part !~ m/^\Q$partid\E/) { next;}
3544: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3545: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3546: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3547: if ($awarded ne '' && $awarded ne $old_aw) {
3548: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3549: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3550: $updateflag=1;
3551: }
1.93 albertel 3552: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3553: '<td align="center">'.$awarded.' </td>';
3554: }
1.44 ng 3555: }
1.477 albertel 3556: $line.="\n";
1.301 albertel 3557:
3558: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3559: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3560:
1.44 ng 3561: if ($updateflag) {
3562: $count++;
1.257 albertel 3563: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3564: $udom,$uname);
1.301 albertel 3565:
3566: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3567: $cnum,$udom,$uname)) {
3568: # need to figure out if should be in queue.
3569: my %record =
3570: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3571: $udom,$uname);
3572: my $all_graded = 1;
3573: my $none_graded = 1;
3574: foreach my $part (@parts) {
3575: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3576: $all_graded = 0;
3577: } else {
3578: $none_graded = 0;
3579: }
3580: }
3581:
3582: if ($all_graded || $none_graded) {
3583: &Apache::bridgetask::remove_from_queue('gradingqueue',
3584: $symb,$cdom,$cnum,
3585: $udom,$uname);
3586: }
3587: }
3588:
1.477 albertel 3589: $result.=&Apache::loncommon::start_data_table_row().
3590: '<td align="right"> '.$updateCtr.' </td>'.$line.
3591: &Apache::loncommon::end_data_table_row();
1.126 ng 3592: $updateCtr++;
1.93 albertel 3593: } else {
1.477 albertel 3594: push(@noupdate,
3595: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3596: $noupdateCtr++;
1.44 ng 3597: }
1.269 raeburn 3598: if ($aggregateflag) {
3599: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3600: $cdom,$cnum);
1.269 raeburn 3601: }
1.93 albertel 3602: }
1.477 albertel 3603: if (@noupdate) {
1.126 ng 3604: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3605: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3606: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3607: '<td align="center" colspan="'.$numcols.'">'.
3608: &mt('No Changes Occurred For the Students Below').
3609: '</td>'.
1.477 albertel 3610: &Apache::loncommon::end_data_table_row();
3611: foreach my $line (@noupdate) {
3612: $result.=
3613: &Apache::loncommon::start_data_table_row().
3614: $line.
3615: &Apache::loncommon::end_data_table_row();
3616: }
1.44 ng 3617: }
1.477 albertel 3618: $result .= &Apache::loncommon::end_data_table().
3619: &show_grading_menu_form($symb);
1.478 albertel 3620: my $msg = '<p><b>'.
3621: &mt('Number of records updated = [_1] for [quant,_2,student].',
3622: $rec_update,$count).'</b><br />'.
3623: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3624: '</b></p>';
1.44 ng 3625: return $title.$msg.$result;
1.5 albertel 3626: }
1.54 albertel 3627:
3628: sub split_part_type {
3629: my ($partstr) = @_;
3630: my ($temp,@allparts)=split(/_/,$partstr);
3631: my $type=pop(@allparts);
1.439 albertel 3632: my $part=join('_',@allparts);
1.54 albertel 3633: return ($part,$type);
3634: }
3635:
1.44 ng 3636: #------------- end of section for handling grading by section/class ---------
3637: #
3638: #----------------------------------------------------------------------------
3639:
1.5 albertel 3640:
1.44 ng 3641: #----------------------------------------------------------------------------
3642: #
3643: #-------------------------- Next few routines handles grading by csv upload
3644: #
3645: #--- Javascript to handle csv upload
1.27 albertel 3646: sub csvupload_javascript_reverse_associate {
1.246 albertel 3647: my $error1=&mt('You need to specify the username or ID');
3648: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3649: return(<<ENDPICK);
3650: function verify(vf) {
3651: var foundsomething=0;
3652: var founduname=0;
1.243 albertel 3653: var foundID=0;
1.27 albertel 3654: for (i=0;i<=vf.nfields.value;i++) {
3655: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3656: if (i==0 && tw!=0) { foundID=1; }
3657: if (i==1 && tw!=0) { founduname=1; }
3658: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3659: }
1.246 albertel 3660: if (founduname==0 && foundID==0) {
3661: alert('$error1');
3662: return;
1.27 albertel 3663: }
3664: if (foundsomething==0) {
1.246 albertel 3665: alert('$error2');
3666: return;
1.27 albertel 3667: }
3668: vf.submit();
3669: }
3670: function flip(vf,tf) {
3671: var nw=eval('vf.f'+tf+'.selectedIndex');
3672: var i;
3673: for (i=0;i<=vf.nfields.value;i++) {
3674: //can not pick the same destination field for both name and domain
3675: if (((i ==0)||(i ==1)) &&
3676: ((tf==0)||(tf==1)) &&
3677: (i!=tf) &&
3678: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3679: eval('vf.f'+i+'.selectedIndex=0;')
3680: }
3681: }
3682: }
3683: ENDPICK
3684: }
3685:
3686: sub csvupload_javascript_forward_associate {
1.246 albertel 3687: my $error1=&mt('You need to specify the username or ID');
3688: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3689: return(<<ENDPICK);
3690: function verify(vf) {
3691: var foundsomething=0;
3692: var founduname=0;
1.243 albertel 3693: var foundID=0;
1.27 albertel 3694: for (i=0;i<=vf.nfields.value;i++) {
3695: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3696: if (tw==1) { foundID=1; }
3697: if (tw==2) { founduname=1; }
3698: if (tw>3) { foundsomething=1; }
1.27 albertel 3699: }
1.246 albertel 3700: if (founduname==0 && foundID==0) {
3701: alert('$error1');
3702: return;
1.27 albertel 3703: }
3704: if (foundsomething==0) {
1.246 albertel 3705: alert('$error2');
3706: return;
1.27 albertel 3707: }
3708: vf.submit();
3709: }
3710: function flip(vf,tf) {
3711: var nw=eval('vf.f'+tf+'.selectedIndex');
3712: var i;
3713: //can not pick the same destination field twice
3714: for (i=0;i<=vf.nfields.value;i++) {
3715: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3716: eval('vf.f'+i+'.selectedIndex=0;')
3717: }
3718: }
3719: }
3720: ENDPICK
3721: }
3722:
1.26 albertel 3723: sub csvuploadmap_header {
1.324 albertel 3724: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3725: my $javascript;
1.257 albertel 3726: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3727: $javascript=&csvupload_javascript_reverse_associate();
3728: } else {
3729: $javascript=&csvupload_javascript_forward_associate();
3730: }
1.45 ng 3731:
1.324 albertel 3732: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3733: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3734: my $ignore=&mt('Ignore First Line');
1.418 albertel 3735: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3736: $request->print(<<ENDPICK);
1.26 albertel 3737: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3738: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3739: $result
1.326 albertel 3740: <hr />
1.26 albertel 3741: <h3>Identify fields</h3>
3742: Total number of records found in file: $distotal <hr />
3743: Enter as many fields as you can. The system will inform you and bring you back
3744: to this page if the data selected is insufficient to run your class.<hr />
3745: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3746: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3747: <input type="hidden" name="associate" value="" />
3748: <input type="hidden" name="phase" value="three" />
3749: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3750: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3751: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3752: <input type="hidden" name="upfile_associate"
1.257 albertel 3753: value="$env{'form.upfile_associate'}" />
1.26 albertel 3754: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3755: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3756: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3757: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3758: <hr />
3759: <script type="text/javascript" language="Javascript">
3760: $javascript
3761: </script>
3762: ENDPICK
1.118 ng 3763: return '';
1.26 albertel 3764:
3765: }
3766:
3767: sub csvupload_fields {
1.324 albertel 3768: my ($symb) = @_;
3769: my (@parts) = &getpartlist($symb);
1.556 ! weissno 3770: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3771: ['username','Student Username'],
3772: ['domain','Student Domain']);
1.324 albertel 3773: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3774: foreach my $part (sort(@parts)) {
3775: my @datum;
3776: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3777: my $name=$part;
3778: if (!$display) { $display = $name; }
3779: @datum=($name,$display);
1.244 albertel 3780: if ($name=~/^stores_(.*)_awarded/) {
3781: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3782: }
1.41 ng 3783: push(@fields,\@datum);
3784: }
3785: return (@fields);
1.26 albertel 3786: }
3787:
3788: sub csvuploadmap_footer {
1.41 ng 3789: my ($request,$i,$keyfields) =@_;
3790: $request->print(<<ENDPICK);
1.26 albertel 3791: </table>
3792: <input type="hidden" name="nfields" value="$i" />
3793: <input type="hidden" name="keyfields" value="$keyfields" />
3794: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3795: </form>
3796: ENDPICK
3797: }
3798:
1.283 albertel 3799: sub checkforfile_js {
1.539 riegler 3800: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 3801: my $result =<<CSVFORMJS;
3802: <script type="text/javascript" language="javascript">
3803: function checkUpload(formname) {
3804: if (formname.upfile.value == "") {
1.539 riegler 3805: alert("$alertmsg");
1.86 ng 3806: return false;
3807: }
3808: formname.submit();
3809: }
3810: </script>
3811: CSVFORMJS
1.283 albertel 3812: return $result;
3813: }
3814:
3815: sub upcsvScores_form {
3816: my ($request) = shift;
1.324 albertel 3817: my ($symb)=&get_symb($request);
1.283 albertel 3818: if (!$symb) {return '';}
3819: my $result=&checkforfile_js();
1.257 albertel 3820: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3821: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3822: $result.=$table;
1.326 albertel 3823: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3824: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3825: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3826: '</b></td></tr>'."\n";
1.86 ng 3827: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3828: my $upload=&mt("Upload Scores");
1.86 ng 3829: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3830: my $ignore=&mt('Ignore First Line');
1.418 albertel 3831: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3832: $result.=<<ENDUPFORM;
1.106 albertel 3833: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3834: <input type="hidden" name="symb" value="$symb" />
3835: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3836: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3837: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3838: $upfile_select
1.370 www 3839: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3840: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3841: </form>
3842: ENDUPFORM
1.370 www 3843: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3844: &mt("How do I create a CSV file from a spreadsheet"))
3845: .'</td></tr></table>'."\n";
1.86 ng 3846: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3847: $result.=&show_grading_menu_form($symb);
1.86 ng 3848: return $result;
3849: }
3850:
3851:
1.26 albertel 3852: sub csvuploadmap {
1.41 ng 3853: my ($request)= @_;
1.324 albertel 3854: my ($symb)=&get_symb($request);
1.41 ng 3855: if (!$symb) {return '';}
1.72 ng 3856:
1.41 ng 3857: my $datatoken;
1.257 albertel 3858: if (!$env{'form.datatoken'}) {
1.41 ng 3859: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3860: } else {
1.257 albertel 3861: $datatoken=$env{'form.datatoken'};
1.41 ng 3862: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3863: }
1.41 ng 3864: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3865: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3866: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3867: my ($i,$keyfields);
3868: if (@records) {
1.324 albertel 3869: my @fields=&csvupload_fields($symb);
1.45 ng 3870:
1.257 albertel 3871: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3872: &Apache::loncommon::csv_print_samples($request,\@records);
3873: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3874: \@fields);
3875: foreach (@fields) { $keyfields.=$_->[0].','; }
3876: chop($keyfields);
3877: } else {
3878: unshift(@fields,['none','']);
3879: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3880: \@fields);
1.311 banghart 3881: foreach my $rec (@records) {
3882: my %temp = &Apache::loncommon::record_sep($rec);
3883: if (%temp) {
3884: $keyfields=join(',',sort(keys(%temp)));
3885: last;
3886: }
3887: }
1.41 ng 3888: }
3889: }
3890: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3891: $request->print(&show_grading_menu_form($symb));
1.72 ng 3892:
1.41 ng 3893: return '';
1.27 albertel 3894: }
3895:
1.246 albertel 3896: sub csvuploadoptions {
1.41 ng 3897: my ($request)= @_;
1.324 albertel 3898: my ($symb)=&get_symb($request);
1.257 albertel 3899: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3900: my $ignore=&mt('Ignore First Line');
3901: $request->print(<<ENDPICK);
3902: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3903: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3904: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3905: <!--
1.246 albertel 3906: <p>
3907: <label>
3908: <input type="checkbox" name="show_full_results" />
3909: Show a table of all changes
3910: </label>
3911: </p>
1.302 albertel 3912: -->
1.246 albertel 3913: <p>
3914: <label>
3915: <input type="checkbox" name="overwite_scores" checked="checked" />
3916: Overwrite any existing score
3917: </label>
3918: </p>
3919: ENDPICK
3920: my %fields=&get_fields();
3921: if (!defined($fields{'domain'})) {
1.257 albertel 3922: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3923: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3924: }
1.257 albertel 3925: foreach my $key (sort(keys(%env))) {
1.246 albertel 3926: if ($key !~ /^form\.(.*)$/) { next; }
3927: my $cleankey=$1;
3928: if ($cleankey eq 'command') { next; }
3929: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3930: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3931: }
3932: # FIXME do a check for any duplicated user ids...
3933: # FIXME do a check for any invalid user ids?...
1.290 albertel 3934: $request->print('<input type="submit" value="Assign Grades" /><br />
3935: <hr /></form>'."\n");
1.324 albertel 3936: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3937: return '';
3938: }
3939:
3940: sub get_fields {
3941: my %fields;
1.257 albertel 3942: my @keyfields = split(/\,/,$env{'form.keyfields'});
3943: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3944: if ($env{'form.upfile_associate'} eq 'reverse') {
3945: if ($env{'form.f'.$i} ne 'none') {
3946: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3947: }
3948: } else {
1.257 albertel 3949: if ($env{'form.f'.$i} ne 'none') {
3950: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3951: }
3952: }
1.27 albertel 3953: }
1.246 albertel 3954: return %fields;
3955: }
3956:
3957: sub csvuploadassign {
3958: my ($request)= @_;
1.324 albertel 3959: my ($symb)=&get_symb($request);
1.246 albertel 3960: if (!$symb) {return '';}
1.345 bowersj2 3961: my $error_msg = '';
1.246 albertel 3962: &Apache::loncommon::load_tmp_file($request);
3963: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3964: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3965: my %fields=&get_fields();
1.41 ng 3966: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3967: my $courseid=$env{'request.course.id'};
1.97 albertel 3968: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3969: my @notallowed;
1.41 ng 3970: my @skipped;
3971: my $countdone=0;
3972: foreach my $grade (@gradedata) {
3973: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3974: my $domain;
3975: if ($entries{$fields{'domain'}}) {
3976: $domain=$entries{$fields{'domain'}};
3977: } else {
1.257 albertel 3978: $domain=$env{'form.default_domain'};
1.246 albertel 3979: }
1.243 albertel 3980: $domain=~s/\s//g;
1.41 ng 3981: my $username=$entries{$fields{'username'}};
1.160 albertel 3982: $username=~s/\s//g;
1.243 albertel 3983: if (!$username) {
3984: my $id=$entries{$fields{'ID'}};
1.247 albertel 3985: $id=~s/\s//g;
1.243 albertel 3986: my %ids=&Apache::lonnet::idget($domain,$id);
3987: $username=$ids{$id};
3988: }
1.41 ng 3989: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3990: my $id=$entries{$fields{'ID'}};
3991: $id=~s/\s//g;
3992: if ($id) {
3993: push(@skipped,"$id:$domain");
3994: } else {
3995: push(@skipped,"$username:$domain");
3996: }
1.41 ng 3997: next;
3998: }
1.108 albertel 3999: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4000: if (!&canmodify($usec)) {
4001: push(@notallowed,"$username:$domain");
4002: next;
4003: }
1.244 albertel 4004: my %points;
1.41 ng 4005: my %grades;
4006: foreach my $dest (keys(%fields)) {
1.244 albertel 4007: if ($dest eq 'ID' || $dest eq 'username' ||
4008: $dest eq 'domain') { next; }
4009: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4010: if ($dest=~/stores_(.*)_points/) {
4011: my $part=$1;
4012: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4013: $symb,$domain,$username);
1.345 bowersj2 4014: if ($wgt) {
4015: $entries{$fields{$dest}}=~s/\s//g;
4016: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4017: my $award=($pcr == 0) ? 'incorrect_by_override'
4018: : 'correct_by_override';
1.345 bowersj2 4019: $grades{"resource.$part.awarded"}=$pcr;
4020: $grades{"resource.$part.solved"}=$award;
4021: $points{$part}=1;
4022: } else {
4023: $error_msg = "<br />" .
4024: &mt("Some point values were assigned"
4025: ." for problems with a weight "
4026: ."of zero. These values were "
4027: ."ignored.");
4028: }
1.244 albertel 4029: } else {
4030: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4031: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4032: my $store_key=$dest;
4033: $store_key=~s/^stores/resource/;
4034: $store_key=~s/_/\./g;
4035: $grades{$store_key}=$entries{$fields{$dest}};
4036: }
1.41 ng 4037: }
1.508 www 4038: if (! %grades) {
4039: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4040: } else {
4041: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4042: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4043: $env{'request.course.id'},
4044: $domain,$username);
1.508 www 4045: if ($result eq 'ok') {
4046: $request->print('.');
4047: } else {
4048: $request->print("<p><span class=\"LC_error\">".
4049: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4050: "$username:$domain",$result)."</span></p>");
4051: }
4052: $request->rflush();
4053: $countdone++;
4054: }
1.41 ng 4055: }
1.508 www 4056: $request->print('<br /><span class="LC_info">'.&mt("Saved [_1] students",$countdone)."</span>\n");
1.41 ng 4057: if (@skipped) {
1.508 www 4058: $request->print('<p><span class="LC_warning">'.&mt('Skipped Students').'</span></p>');
1.106 albertel 4059: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
4060: }
4061: if (@notallowed) {
1.508 www 4062: $request->print('<p><span class="LC_error">'.&mt('Students Not Allowed to Modify').'</span></p>');
1.106 albertel 4063: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 4064: }
1.106 albertel 4065: $request->print("<br />\n");
1.324 albertel 4066: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4067: return $error_msg;
1.26 albertel 4068: }
1.44 ng 4069: #------------- end of section for handling csv file upload ---------
4070: #
4071: #-------------------------------------------------------------------
4072: #
1.122 ng 4073: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4074: #
4075: #--- Select a page/sequence and a student to grade
1.68 ng 4076: sub pickStudentPage {
4077: my ($request) = shift;
4078:
1.539 riegler 4079: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4080: $request->print(<<LISTJAVASCRIPT);
4081: <script type="text/javascript" language="javascript">
4082:
4083: function checkPickOne(formname) {
1.76 ng 4084: if (radioSelection(formname.student) == null) {
1.539 riegler 4085: alert("$alertmsg");
1.68 ng 4086: return;
4087: }
1.125 ng 4088: ptr = pullDownSelection(formname.selectpage);
4089: formname.page.value = formname["page"+ptr].value;
4090: formname.title.value = formname["title"+ptr].value;
1.68 ng 4091: formname.submit();
4092: }
4093:
4094: </script>
4095: LISTJAVASCRIPT
1.118 ng 4096: &commonJSfunctions($request);
1.324 albertel 4097: my ($symb) = &get_symb($request);
1.257 albertel 4098: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4099: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4100: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4101:
1.398 albertel 4102: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4103: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4104:
1.80 ng 4105: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.423 albertel 4106: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4107: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4108: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4109: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4110: my $select = '<select name="selectpage">'."\n";
1.70 ng 4111: my $ctr=0;
1.68 ng 4112: foreach (@$titles) {
4113: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4114: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4115: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4116: '>'.$showtitle.'</option>'."\n";
1.70 ng 4117: $ctr++;
1.68 ng 4118: }
1.485 albertel 4119: $select.= '</select>';
1.539 riegler 4120: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4121:
1.70 ng 4122: $ctr=0;
4123: foreach (@$titles) {
4124: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4125: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4126: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4127: $ctr++;
4128: }
1.72 ng 4129: $result.='<input type="hidden" name="page" />'."\n".
4130: '<input type="hidden" name="title" />'."\n";
1.68 ng 4131:
1.485 albertel 4132: my $options =
4133: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4134: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4135: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4136:
4137: $options =
4138: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4139: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4140: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4141: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4142:
4143: $result.=&build_section_inputs();
1.442 banghart 4144: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4145: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4146: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4147: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4148: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4149:
1.539 riegler 4150: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4151:
1.80 ng 4152: $result.=' <input type="button" '.
1.539 riegler 4153: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4154:
1.68 ng 4155: $request->print($result);
4156:
1.485 albertel 4157: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4158: &Apache::loncommon::start_data_table().
4159: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4160: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4161: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4162: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4163: '<th>'.&nameUserString('header').'</th>'.
4164: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4165:
1.76 ng 4166: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4167: my $ptr = 1;
1.294 albertel 4168: foreach my $student (sort
4169: {
4170: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4171: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4172: }
4173: return $a cmp $b;
4174: } (keys(%$fullname))) {
1.68 ng 4175: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4176: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4177: : '</td>');
1.126 ng 4178: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4179: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4180: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4181: $studentTable.=
4182: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4183: : '');
1.68 ng 4184: $ptr++;
4185: }
1.484 albertel 4186: if ($ptr%2 == 0) {
4187: $studentTable.='</td><td> </td><td> </td>'.
4188: &Apache::loncommon::end_data_table_row();
4189: }
4190: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4191: $studentTable.='<input type="button" '.
1.539 riegler 4192: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4193:
1.324 albertel 4194: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4195: $request->print($studentTable);
4196:
4197: return '';
4198: }
4199:
4200: sub getSymbMap {
1.132 bowersj2 4201: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 4202:
4203: my %symbx = ();
4204: my @titles = ();
1.117 bowersj2 4205: my $minder = 0;
4206:
4207: # Gather every sequence that has problems.
1.240 albertel 4208: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4209: 1,0,1);
1.117 bowersj2 4210: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4211: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4212: my $title = $minder.'.'.
4213: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4214: push(@titles, $title); # minder in case two titles are identical
4215: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4216: $minder++;
1.241 albertel 4217: }
1.68 ng 4218: }
4219: return \@titles,\%symbx;
4220: }
4221:
1.72 ng 4222: #
4223: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4224: sub displayPage {
4225: my ($request) = shift;
4226:
1.324 albertel 4227: my ($symb) = &get_symb($request);
1.257 albertel 4228: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4229: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4230: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4231: my $pageTitle = $env{'form.page'};
1.103 albertel 4232: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4233: my ($uname,$udom) = split(/:/,$env{'form.student'});
4234: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4235:
4236: #need to make sure we have the correct data for later EXT calls,
4237: #thus invalidate the cache
4238: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4239: $env{'course.'.$env{'request.course.id'}.'.num'},
4240: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4241: &Apache::lonnet::clear_EXT_cache_status();
4242:
1.103 albertel 4243: if (!&canview($usec)) {
1.485 albertel 4244: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4245: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4246: return;
4247: }
1.398 albertel 4248: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4249: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4250: '</h3>'."\n";
1.500 albertel 4251: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4252: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4253: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4254: } else {
4255: delete($env{'form.CODE'});
4256: }
1.71 ng 4257: &sub_page_js($request);
4258: $request->print($result);
4259:
1.132 bowersj2 4260: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4261: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4262: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4263: if (!$map) {
1.485 albertel 4264: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4265: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4266: return;
4267: }
1.68 ng 4268: my $iterator = $navmap->getIterator($map->map_start(),
4269: $map->map_finish());
4270:
1.71 ng 4271: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4272: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4273: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4274: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4275: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4276: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4277: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4278: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4279: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4280:
1.382 albertel 4281: if (defined($env{'form.CODE'})) {
4282: $studentTable.=
4283: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4284: }
1.381 albertel 4285: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4286: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4287:
1.485 albertel 4288: $studentTable.=' '.&mt('<b>Note:</b> Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon)."\n".
1.484 albertel 4289: &Apache::loncommon::start_data_table().
4290: &Apache::loncommon::start_data_table_header_row().
4291: '<th align="center"> Prob. </th>'.
1.485 albertel 4292: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4293: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4294:
1.329 albertel 4295: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4296: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4297: $iterator->next(); # skip the first BEGIN_MAP
4298: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4299: while ($depth > 0) {
1.68 ng 4300: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4301: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4302:
1.385 albertel 4303: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4304: my $parts = $curRes->parts();
1.68 ng 4305: my $title = $curRes->compTitle();
1.71 ng 4306: my $symbx = $curRes->symb();
1.484 albertel 4307: $studentTable.=
4308: &Apache::loncommon::start_data_table_row().
4309: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4310: (scalar(@{$parts}) == 1 ? ''
4311: : '<br />('.&mt('[_1] parts)',
4312: scalar(@{$parts}))
4313: ).
4314: '</td>';
1.71 ng 4315: $studentTable.='<td valign="top">';
1.382 albertel 4316: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4317: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4318: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4319: undef,'both',\%form);
1.71 ng 4320: } else {
1.382 albertel 4321: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4322: $companswer =~ s|<form(.*?)>||g;
4323: $companswer =~ s|</form>||g;
1.71 ng 4324: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4325: # $companswer =~ s/$1/ /ms;
1.326 albertel 4326: # $request->print('match='.$1."<br />\n");
1.71 ng 4327: # }
1.116 ng 4328: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4329: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4330: }
4331:
1.257 albertel 4332: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4333:
1.257 albertel 4334: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4335: if ($record{'version'} eq '') {
1.485 albertel 4336: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4337: } else {
1.116 ng 4338: my %responseType = ();
4339: foreach my $partid (@{$parts}) {
1.147 albertel 4340: my @responseIds =$curRes->responseIds($partid);
4341: my @responseType =$curRes->responseType($partid);
4342: my %responseIds;
4343: for (my $i=0;$i<=$#responseIds;$i++) {
4344: $responseIds{$responseIds[$i]}=$responseType[$i];
4345: }
4346: $responseType{$partid} = \%responseIds;
1.116 ng 4347: }
1.148 albertel 4348: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4349:
1.71 ng 4350: }
1.257 albertel 4351: } elsif ($env{'form.lastSub'} eq 'all') {
4352: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4353: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4354: $env{'request.course.id'},
1.71 ng 4355: '','.submission');
4356:
4357: }
1.103 albertel 4358: if (&canmodify($usec)) {
4359: foreach my $partid (@{$parts}) {
4360: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4361: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4362: $question++;
4363: }
1.196 albertel 4364: $prob++;
1.71 ng 4365: }
4366: $studentTable.='</td></tr>';
1.68 ng 4367:
1.103 albertel 4368: }
1.68 ng 4369: $curRes = $iterator->next();
4370: }
4371:
1.485 albertel 4372: $studentTable.='</table>'."\n".
4373: '<input type="button" value="'.&mt('Save').'" '.
1.381 albertel 4374: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4375: '</form>'."\n";
1.324 albertel 4376: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4377: $request->print($studentTable);
4378:
4379: return '';
1.119 ng 4380: }
4381:
4382: sub displaySubByDates {
1.148 albertel 4383: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4384: my $isCODE=0;
1.335 albertel 4385: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4386: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4387: my $studentTable=&Apache::loncommon::start_data_table().
4388: &Apache::loncommon::start_data_table_header_row().
4389: '<th>'.&mt('Date/Time').'</th>'.
4390: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4391: '<th>'.&mt('Submission').'</th>'.
4392: '<th>'.&mt('Status').'</th>'.
4393: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4394: my ($version);
4395: my %mark;
1.148 albertel 4396: my %orders;
1.119 ng 4397: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4398: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4399: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4400: }
1.335 albertel 4401:
4402: my $interaction;
1.525 raeburn 4403: my $no_increment = 1;
1.119 ng 4404: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4405: my $timestamp =
4406: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4407: if (exists($$record{$version.':resource.0.version'})) {
4408: $interaction = $$record{$version.':resource.0.version'};
4409: }
4410:
4411: my $where = ($isTask ? "$version:resource.$interaction"
4412: : "$version:resource");
1.467 albertel 4413: $studentTable.=&Apache::loncommon::start_data_table_row().
4414: '<td>'.$timestamp.'</td>';
1.224 albertel 4415: if ($isCODE) {
4416: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4417: }
1.119 ng 4418: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4419: my @displaySub = ();
4420: foreach my $partid (@{$parts}) {
1.335 albertel 4421: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4422: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4423:
4424:
1.122 ng 4425: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4426: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4427: foreach my $matchKey (@matchKey) {
1.198 albertel 4428: if (exists($$record{$version.':'.$matchKey}) &&
4429: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4430:
4431: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4432: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.467 albertel 4433: $displaySub[0].='<b>'.&mt('Part:').'</b> '.$display_part.' ';
4434: $displaySub[0].='<span class="LC_internal_info">('.&mt('ID').' '.
1.398 albertel 4435: $responseId.')</span> <b>';
1.335 albertel 4436: if ($$record{"$where.$partid.tries"} eq '') {
1.467 albertel 4437: $displaySub[0].=&mt('Trial not counted');
1.147 albertel 4438: } else {
1.467 albertel 4439: $displaySub[0].=&mt('Trial [_1]',
4440: $$record{"$where.$partid.tries"});
1.147 albertel 4441: }
1.335 albertel 4442: my $responseType=($isTask ? 'Task'
4443: : $responseType->{$partid}->{$responseId});
1.148 albertel 4444: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4445: if (!exists($orders{$partid}->{$responseId})) {
4446: $orders{$partid}->{$responseId}=
1.525 raeburn 4447: &get_order($partid,$responseId,$symb,$uname,$udom,
4448: $no_increment);
1.148 albertel 4449: }
1.147 albertel 4450: $displaySub[0].='</b> '.
1.336 albertel 4451: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4452: }
4453: }
1.335 albertel 4454: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4455: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4456: $$record{"$where.$partid.checkedin"},
4457: $$record{"$where.$partid.checkedin.slot"}).
4458: '<br />';
1.335 albertel 4459: }
4460: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4461: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4462: lc($$record{"$where.$partid.award"}).' '.
4463: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4464: '<br />';
4465: }
1.335 albertel 4466: if (exists $$record{"$where.$partid.regrader"}) {
4467: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4468: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4469: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4470: $displaySub[2].=
4471: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4472: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4473: }
4474: }
4475: # needed because old essay regrader has not parts info
4476: if (exists $$record{"$version:resource.regrader"}) {
4477: $displaySub[2].=$$record{"$version:resource.regrader"};
4478: }
4479: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4480: if ($displaySub[2]) {
1.467 albertel 4481: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4482: }
1.467 albertel 4483: $studentTable.=' </td>'.
4484: &Apache::loncommon::end_data_table_row();
1.119 ng 4485: }
1.467 albertel 4486: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4487: return $studentTable;
1.71 ng 4488: }
4489:
4490: sub updateGradeByPage {
4491: my ($request) = shift;
4492:
1.257 albertel 4493: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4494: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4495: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4496: my $pageTitle = $env{'form.page'};
1.103 albertel 4497: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4498: my ($uname,$udom) = split(/:/,$env{'form.student'});
4499: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4500: if (!&canmodify($usec)) {
1.526 raeburn 4501: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4502: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4503: return;
4504: }
1.398 albertel 4505: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4506: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4507: '</h3>'."\n";
1.70 ng 4508:
1.68 ng 4509: $request->print($result);
4510:
1.132 bowersj2 4511: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4512: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4513: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4514: if (!$map) {
1.527 raeburn 4515: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4516: my ($symb)=&get_symb($request);
4517: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4518: return;
4519: }
1.71 ng 4520: my $iterator = $navmap->getIterator($map->map_start(),
4521: $map->map_finish());
1.70 ng 4522:
1.484 albertel 4523: my $studentTable=
4524: &Apache::loncommon::start_data_table().
4525: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4526: '<th align="center"> '.&mt('Prob.').' </th>'.
4527: '<th> '.&mt('Title').' </th>'.
4528: '<th> '.&mt('Previous Score').' </th>'.
4529: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4530: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4531:
4532: $iterator->next(); # skip the first BEGIN_MAP
4533: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4534: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4535: while ($depth > 0) {
1.71 ng 4536: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4537: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4538:
1.385 albertel 4539: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4540: my $parts = $curRes->parts();
1.71 ng 4541: my $title = $curRes->compTitle();
4542: my $symbx = $curRes->symb();
1.484 albertel 4543: $studentTable.=
4544: &Apache::loncommon::start_data_table_row().
4545: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4546: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4547: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4548: .')').'</td>';
1.71 ng 4549: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4550:
4551: my %newrecord=();
4552: my @displayPts=();
1.269 raeburn 4553: my %aggregate = ();
4554: my $aggregateflag = 0;
1.71 ng 4555: foreach my $partid (@{$parts}) {
1.257 albertel 4556: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4557: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4558:
1.257 albertel 4559: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4560: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4561: my $partial = $newpts/$wgt;
4562: my $score;
4563: if ($partial > 0) {
4564: $score = 'correct_by_override';
1.125 ng 4565: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4566: $score = 'incorrect_by_override';
4567: }
1.257 albertel 4568: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4569: if ($dropMenu eq 'excused') {
1.71 ng 4570: $partial = '';
4571: $score = 'excused';
1.125 ng 4572: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4573: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4574: $newrecord{'resource.'.$partid.'.tries'} = 0;
4575: $newrecord{'resource.'.$partid.'.solved'} = '';
4576: $newrecord{'resource.'.$partid.'.award'} = '';
4577: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4578: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4579: $changeflag++;
4580: $newpts = '';
1.269 raeburn 4581:
4582: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4583: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4584: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4585: if ($aggtries > 0) {
4586: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4587: $aggregateflag = 1;
4588: }
1.71 ng 4589: }
1.324 albertel 4590: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4591: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4592: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4593: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4594: ' <br />';
1.526 raeburn 4595: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4596: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4597: ' <br />';
1.71 ng 4598: $question++;
1.380 albertel 4599: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4600:
1.71 ng 4601: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4602: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4603: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4604: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4605:
4606: $changeflag++;
4607: }
4608: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4609: my %record =
4610: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4611: $udom,$uname);
4612:
4613: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4614: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4615: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4616: $newrecord{'resource.CODE'} = '';
4617: }
1.257 albertel 4618: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4619: $udom,$uname);
1.382 albertel 4620: %record = &Apache::lonnet::restore($symbx,
4621: $env{'request.course.id'},
4622: $udom,$uname);
1.380 albertel 4623: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4624: $cdom,$cnum,$udom,$uname);
1.71 ng 4625: }
1.380 albertel 4626:
1.269 raeburn 4627: if ($aggregateflag) {
4628: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4629: $env{'course.'.$env{'request.course.id'}.'.domain'},
4630: $env{'course.'.$env{'request.course.id'}.'.num'});
4631: }
1.125 ng 4632:
1.71 ng 4633: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4634: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4635: &Apache::loncommon::end_data_table_row();
1.68 ng 4636:
1.196 albertel 4637: $prob++;
1.68 ng 4638: }
1.71 ng 4639: $curRes = $iterator->next();
1.68 ng 4640: }
1.98 albertel 4641:
1.484 albertel 4642: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4643: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4644: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4645: &mt('The scores were changed for [quant,_1,problem].',
4646: $changeflag));
1.76 ng 4647: $request->print($grademsg.$studentTable);
1.68 ng 4648:
1.70 ng 4649: return '';
4650: }
4651:
1.72 ng 4652: #-------- end of section for handling grading by page/sequence ---------
4653: #
4654: #-------------------------------------------------------------------
4655:
1.75 albertel 4656: #--------------------Scantron Grading-----------------------------------
4657: #
4658: #------ start of section for handling grading by page/sequence ---------
4659:
1.423 albertel 4660: =pod
4661:
4662: =head1 Bubble sheet grading routines
4663:
1.424 albertel 4664: For this documentation:
4665:
4666: 'scanline' refers to the full line of characters
4667: from the file that we are parsing that represents one entire sheet
4668:
4669: 'bubble line' refers to the data
4670: representing the line of bubbles that are on the physical bubble sheet
4671:
4672:
4673: The overall process is that a scanned in bubble sheet data is uploaded
4674: into a course. When a user wants to grade, they select a
4675: sequence/folder of resources, a file of bubble sheet info, and pick
4676: one of the predefined configurations for what each scanline looks
4677: like.
4678:
4679: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4680: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4681: because too light bubbling), 'double bubble' (each bubble line should
4682: have no more that one letter picked), invalid or duplicated CODE,
1.556 ! weissno 4683: invalid student/employee ID
1.424 albertel 4684:
4685: If the CODE option is used that determines the randomization of the
1.556 ! weissno 4686: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4687: username:domain.
4688:
4689: During the validation phase the instructor can choose to skip scanlines.
4690:
1.435 foxr 4691: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4692:
4693: scantron_original_filename (unmodified original file)
4694: scantron_corrected_filename (file where the corrected information has replaced the original information)
4695: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4696:
4697: Also there is a separate hash nohist_scantrondata that contains extra
4698: correction information that isn't representable in the bubble sheet
4699: file (see &scantron_getfile() for more information)
4700:
4701: After all scanlines are either valid, marked as valid or skipped, then
4702: foreach line foreach problem in the picked sequence, an ssi request is
4703: made that simulates a user submitting their selected letter(s) against
4704: the homework problem.
1.423 albertel 4705:
4706: =over 4
4707:
4708:
4709:
4710: =item defaultFormData
4711:
4712: Returns html hidden inputs used to hold context/default values.
4713:
4714: Arguments:
4715: $symb - $symb of the current resource
4716:
4717: =cut
1.422 foxr 4718:
1.81 albertel 4719: sub defaultFormData {
1.324 albertel 4720: my ($symb)=@_;
1.447 foxr 4721: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4722: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4723: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4724: }
4725:
1.447 foxr 4726:
1.423 albertel 4727: =pod
4728:
4729: =item getSequenceDropDown
4730:
4731: Return html dropdown of possible sequences to grade
4732:
4733: Arguments:
4734: $symb - $symb of the current resource
4735:
4736: =cut
1.422 foxr 4737:
1.75 albertel 4738: sub getSequenceDropDown {
1.423 albertel 4739: my ($symb)=@_;
1.75 albertel 4740: my $result='<select name="selectpage">'."\n";
1.423 albertel 4741: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4742: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4743: my $ctr=0;
4744: foreach (@$titles) {
4745: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4746: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4747: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4748: '>'.$showtitle.'</option>'."\n";
4749: $ctr++;
4750: }
4751: $result.= '</select>';
4752: return $result;
4753: }
4754:
1.495 albertel 4755: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4756: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4757:
4758: my %first_bubble_line; # First bubble line no. for each bubble.
4759:
1.509 raeburn 4760: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4761: # matchresponse or rankresponse, where
4762: # an individual response can have multiple
4763: # lines
1.503 raeburn 4764:
4765: my %responsetype_per_response; # responsetype for each response
4766:
1.495 albertel 4767: # Save and restore the bubble lines array to the form env.
4768:
4769:
4770: sub save_bubble_lines {
4771: foreach my $line (keys(%bubble_lines_per_response)) {
4772: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4773: $env{"form.scantron.first_bubble_line.$line"} =
4774: $first_bubble_line{$line};
1.503 raeburn 4775: $env{"form.scantron.sub_bubblelines.$line"} =
4776: $subdivided_bubble_lines{$line};
4777: $env{"form.scantron.responsetype.$line"} =
4778: $responsetype_per_response{$line};
1.495 albertel 4779: }
4780: }
4781:
4782:
4783: sub restore_bubble_lines {
4784: my $line = 0;
4785: %bubble_lines_per_response = ();
4786: while ($env{"form.scantron.bubblelines.$line"}) {
4787: my $value = $env{"form.scantron.bubblelines.$line"};
4788: $bubble_lines_per_response{$line} = $value;
4789: $first_bubble_line{$line} =
4790: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4791: $subdivided_bubble_lines{$line} =
4792: $env{"form.scantron.sub_bubblelines.$line"};
4793: $responsetype_per_response{$line} =
4794: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4795: $line++;
4796: }
4797: }
4798:
4799: # Given the parsed scanline, get the response for
4800: # 'answer' number n:
4801:
4802: sub get_response_bubbles {
4803: my ($parsed_line, $response) = @_;
4804:
4805: my $bubble_line = $first_bubble_line{$response-1} +1;
4806: my $bubble_lines= $bubble_lines_per_response{$response-1};
4807:
4808: my $selected = "";
4809:
4810: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4811: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4812: $bubble_line++;
4813: }
4814: return $selected;
4815: }
1.423 albertel 4816:
4817: =pod
4818:
4819: =item scantron_filenames
4820:
4821: Returns a list of the scantron files in the current course
4822:
4823: =cut
1.422 foxr 4824:
1.202 albertel 4825: sub scantron_filenames {
1.257 albertel 4826: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4827: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4828: my $getpropath = 1;
1.157 albertel 4829: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4830: $getpropath);
1.202 albertel 4831: my @possiblenames;
1.201 albertel 4832: foreach my $filename (sort(@files)) {
1.157 albertel 4833: ($filename)=split(/&/,$filename);
4834: if ($filename!~/^scantron_orig_/) { next ; }
4835: $filename=~s/^scantron_orig_//;
1.202 albertel 4836: push(@possiblenames,$filename);
4837: }
4838: return @possiblenames;
4839: }
4840:
1.423 albertel 4841: =pod
4842:
4843: =item scantron_uploads
4844:
4845: Returns html drop-down list of scantron files in current course.
4846:
4847: Arguments:
4848: $file2grade - filename to set as selected in the dropdown
4849:
4850: =cut
1.422 foxr 4851:
1.202 albertel 4852: sub scantron_uploads {
1.209 ng 4853: my ($file2grade) = @_;
1.202 albertel 4854: my $result= '<select name="scantron_selectfile">';
4855: $result.="<option></option>";
4856: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4857: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4858: }
4859: $result.="</select>";
4860: return $result;
4861: }
4862:
1.423 albertel 4863: =pod
4864:
4865: =item scantron_scantab
4866:
4867: Returns html drop down of the scantron formats in the scantronformat.tab
4868: file.
4869:
4870: =cut
1.422 foxr 4871:
1.82 albertel 4872: sub scantron_scantab {
4873: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4874: $result.='<option></option>'."\n";
1.518 raeburn 4875: my @lines = &get_scantronformat_file();
4876: if (@lines > 0) {
4877: foreach my $line (@lines) {
4878: next if (($line =~ /^\#/) || ($line eq ''));
4879: my ($name,$descrip)=split(/:/,$line);
4880: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4881: }
1.82 albertel 4882: }
4883: $result.='</select>'."\n";
1.518 raeburn 4884: return $result;
4885: }
4886:
4887: =pod
4888:
4889: =item get_scantronformat_file
4890:
4891: Returns an array containing lines from the scantron format file for
4892: the domain of the course.
4893:
4894: If a url for a custom.tab file is listed in domain's configuration.db,
4895: lines are from this file.
4896:
4897: Otherwise, if a default.tab has been published in RES space by the
4898: domainconfig user, lines are from this file.
4899:
4900: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 4901: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 4902:
1.518 raeburn 4903: =cut
4904:
4905: sub get_scantronformat_file {
4906: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4907: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
4908: my $gottab = 0;
4909: my @lines;
4910: if (ref($domconfig{'scantron'}) eq 'HASH') {
4911: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4912: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
4913: if ($formatfile ne '-1') {
4914: @lines = split("\n",$formatfile,-1);
4915: $gottab = 1;
4916: }
4917: }
4918: }
4919: if (!$gottab) {
4920: my $confname = $cdom.'-domainconfig';
4921: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
4922: my $formatfile = &Apache::lonnet::getfile($default);
4923: if ($formatfile ne '-1') {
4924: @lines = split("\n",$formatfile,-1);
4925: $gottab = 1;
4926: }
4927: }
4928: if (!$gottab) {
1.519 raeburn 4929: my @domains = &Apache::lonnet::current_machine_domains();
4930: if (grep(/^\Q$cdom\E$/,@domains)) {
4931: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4932: @lines = <$fh>;
4933: close($fh);
4934: } else {
4935: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
4936: @lines = <$fh>;
4937: close($fh);
4938: }
1.518 raeburn 4939: }
4940: return @lines;
1.82 albertel 4941: }
4942:
1.423 albertel 4943: =pod
4944:
4945: =item scantron_CODElist
4946:
4947: Returns html drop down of the saved CODE lists from current course,
4948: generated from earlier printings.
4949:
4950: =cut
1.422 foxr 4951:
1.186 albertel 4952: sub scantron_CODElist {
1.257 albertel 4953: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4954: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4955: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4956: my $namechoice='<option></option>';
1.225 albertel 4957: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4958: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4959: if ($name =~ /^type\0/) { next; }
1.186 albertel 4960: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4961: }
4962: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4963: return $namechoice;
4964: }
4965:
1.423 albertel 4966: =pod
4967:
4968: =item scantron_CODEunique
4969:
4970: Returns the html for "Each CODE to be used once" radio.
4971:
4972: =cut
1.422 foxr 4973:
1.186 albertel 4974: sub scantron_CODEunique {
1.532 bisitz 4975: my $result='<span class="LC_nobreak">
1.272 albertel 4976: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4977: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 4978: </span>
1.532 bisitz 4979: <span class="LC_nobreak">
1.272 albertel 4980: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4981: value="no" />'.&mt('No').' </label>
1.381 albertel 4982: </span>';
1.186 albertel 4983: return $result;
4984: }
1.423 albertel 4985:
4986: =pod
4987:
4988: =item scantron_selectphase
4989:
4990: Generates the initial screen to start the bubble sheet process.
4991: Allows for - starting a grading run.
1.424 albertel 4992: - downloading existing scan data (original, corrected
1.423 albertel 4993: or skipped info)
4994:
4995: - uploading new scan data
4996:
4997: Arguments:
4998: $r - The Apache request object
4999: $file2grade - name of the file that contain the scanned data to score
5000:
5001: =cut
1.186 albertel 5002:
1.75 albertel 5003: sub scantron_selectphase {
1.209 ng 5004: my ($r,$file2grade) = @_;
1.324 albertel 5005: my ($symb)=&get_symb($r);
1.75 albertel 5006: if (!$symb) {return '';}
1.423 albertel 5007: my $sequence_selector=&getSequenceDropDown($symb);
1.324 albertel 5008: my $default_form_data=&defaultFormData($symb);
5009: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5010: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5011: my $format_selector=&scantron_scantab();
1.186 albertel 5012: my $CODE_selector=&scantron_CODElist();
5013: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5014: my $result;
1.422 foxr 5015:
1.513 foxr 5016: $ssi_error = 0;
5017:
1.422 foxr 5018: # Chunk of form to prompt for a file to grade and how:
5019:
1.489 albertel 5020: $result.= '
5021: <br />
5022: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5023: <input type="hidden" name="command" value="scantron_warning" />
5024: '.$default_form_data.'
5025: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5026: '.&Apache::loncommon::start_data_table_header_row().'
5027: <th colspan="2">
1.492 albertel 5028: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5029: </th>
5030: '.&Apache::loncommon::end_data_table_header_row().'
5031: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5032: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5033: '.&Apache::loncommon::end_data_table_row().'
5034: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5035: <td> '.&mt('Filename of scoring office file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5036: '.&Apache::loncommon::end_data_table_row().'
5037: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5038: <td> '.&mt('Format of data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5039: '.&Apache::loncommon::end_data_table_row().'
5040: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5041: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5042: '.&Apache::loncommon::end_data_table_row().'
5043: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5044: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5045: '.&Apache::loncommon::end_data_table_row().'
5046: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5047: <td> '.&mt('Options:').' </td>
1.187 albertel 5048: <td>
1.492 albertel 5049: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5050: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5051: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5052: </td>
1.489 albertel 5053: '.&Apache::loncommon::end_data_table_row().'
5054: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5055: <td colspan="2">
1.492 albertel 5056: <input type="submit" value="'.&mt('Grading: Validate Scantron Records').'" />
1.162 albertel 5057: </td>
1.489 albertel 5058: '.&Apache::loncommon::end_data_table_row().'
5059: '.&Apache::loncommon::end_data_table().'
5060: </form>
5061: ';
1.162 albertel 5062:
5063: $r->print($result);
5064:
1.257 albertel 5065: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5066: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5067:
1.422 foxr 5068: # Chunk of form to prompt for a scantron file upload.
5069:
1.489 albertel 5070: $r->print('
5071: <br />
5072: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5073: '.&Apache::loncommon::start_data_table_header_row().'
5074: <th>
1.492 albertel 5075: '.&mt('Specify a Scantron data file to upload.').'
1.489 albertel 5076: </th>
5077: '.&Apache::loncommon::end_data_table_header_row().'
5078: '.&Apache::loncommon::start_data_table_row().'
1.162 albertel 5079: <td>
1.489 albertel 5080: ');
1.324 albertel 5081: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5082: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5083: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.492 albertel 5084: $r->print('
1.174 albertel 5085: <script type="text/javascript" language="javascript">
5086: function checkUpload(formname) {
5087: if (formname.upfile.value == "") {
1.492 albertel 5088: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.174 albertel 5089: return false;
5090: }
5091: formname.submit();
5092: }
5093: </script>
5094:
1.492 albertel 5095: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5096: '.$default_form_data.'
5097: <input name="courseid" type="hidden" value="'.$cnum.'" />
5098: <input name="domainid" type="hidden" value="'.$cdom.'" />
5099: <input name="command" value="scantronupload_save" type="hidden" />
5100: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
1.174 albertel 5101: <br />
1.492 albertel 5102: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Scantron Data').'" />
1.174 albertel 5103: </form>
1.492 albertel 5104: ');
1.162 albertel 5105:
1.489 albertel 5106: $r->print('
1.162 albertel 5107: </td>
1.489 albertel 5108: '.&Apache::loncommon::end_data_table_row().'
5109: '.&Apache::loncommon::end_data_table().'
5110: ');
1.162 albertel 5111: }
1.422 foxr 5112:
5113: # Chunk of the form that prompts to view a scoring office file,
5114: # corrected file, skipped records in a file.
5115:
1.489 albertel 5116: $r->print('
5117: <br />
5118: <form action="/adm/grades" name="scantron_download">
5119: '.$default_form_data.'
5120: <input type="hidden" name="command" value="scantron_download" />
5121: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5122: '.&Apache::loncommon::start_data_table_header_row().'
5123: <th>
1.492 albertel 5124: '.&mt('Download a scoring office file').'
1.489 albertel 5125: </th>
5126: '.&Apache::loncommon::end_data_table_header_row().'
5127: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5128: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5129: <br />
1.492 albertel 5130: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5131: '.&Apache::loncommon::end_data_table_row().'
5132: '.&Apache::loncommon::end_data_table().'
5133: </form>
5134: <br />
5135: ');
1.162 albertel 5136:
1.457 banghart 5137: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5138:
1.528 raeburn 5139: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5140: $default_form_data."\n".
5141: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5142: &Apache::loncommon::start_data_table_header_row()."\n".
5143: '<th colspan="2">
5144: '.&mt('Review scantron data and submissions for a previously graded folder/sequence')."\n".
5145: '</th>'."\n".
5146: &Apache::loncommon::end_data_table_header_row()."\n".
5147: &Apache::loncommon::start_data_table_row()."\n".
5148: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5149: '<td> '.$sequence_selector.' </td>'.
5150: &Apache::loncommon::end_data_table_row()."\n".
5151: &Apache::loncommon::start_data_table_row()."\n".
5152: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5153: '<td> '.$file_selector.' </td>'."\n".
5154: &Apache::loncommon::end_data_table_row()."\n".
5155: &Apache::loncommon::start_data_table_row()."\n".
5156: '<td> '.&mt('Format of data file:').' </td>'."\n".
5157: '<td> '.$format_selector.' </td>'."\n".
5158: &Apache::loncommon::end_data_table_row()."\n".
5159: &Apache::loncommon::start_data_table_row()."\n".
5160: '<td colspan="2">'."\n".
5161: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
5162: '<input type="submit" value="'.&mt('Review Scantron Data and Submission Records').'" />'."\n".
5163: '</td>'."\n".
5164: &Apache::loncommon::end_data_table_row()."\n".
5165: &Apache::loncommon::end_data_table()."\n".
5166: '</form><br />');
1.457 banghart 5167: $r->print($grading_menu_button);
1.523 raeburn 5168: return;
1.75 albertel 5169: }
5170:
1.423 albertel 5171: =pod
5172:
5173: =item get_scantron_config
5174:
5175: Parse and return the scantron configuration line selected as a
5176: hash of configuration file fields.
5177:
5178: Arguments:
5179: which - the name of the configuration to parse from the file.
5180:
5181:
5182: Returns:
5183: If the named configuration is not in the file, an empty
5184: hash is returned.
5185: a hash with the fields
5186: name - internal name for the this configuration setup
5187: description - text to display to operator that describes this config
5188: CODElocation - if 0 or the string 'none'
5189: - no CODE exists for this config
5190: if -1 || the string 'letter'
5191: - a CODE exists for this config and is
5192: a string of letters
5193: Unsupported value (but planned for future support)
5194: if a positive integer
5195: - The CODE exists as the first n items from
5196: the question section of the form
5197: if the string 'number'
5198: - The CODE exists for this config and is
5199: a string of numbers
5200: CODEstart - (only matter if a CODE exists) column in the line where
5201: the CODE starts
5202: CODElength - length of the CODE
1.556 ! weissno 5203: IDstart - column where the student/employee ID number starts
! 5204: IDlength - length of the student/employee ID info
1.423 albertel 5205: Qstart - column where the information from the bubbled
5206: 'questions' start
5207: Qlength - number of columns comprising a single bubble line from
5208: the sheet. (usually either 1 or 10)
1.424 albertel 5209: Qon - either a single character representing the character used
1.423 albertel 5210: to signal a bubble was chosen in the positional setup, or
5211: the string 'letter' if the letter of the chosen bubble is
5212: in the final, or 'number' if a number representing the
5213: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5214: Qoff - the character used to represent that a bubble was
5215: left blank
1.423 albertel 5216: PaperID - if the scanning process generates a unique number for each
5217: sheet scanned the column that this ID number starts in
5218: PaperIDlength - number of columns that comprise the unique ID number
5219: for the sheet of paper
1.424 albertel 5220: FirstName - column that the first name starts in
1.423 albertel 5221: FirstNameLength - number of columns that the first name spans
5222:
5223: LastName - column that the last name starts in
5224: LastNameLength - number of columns that the last name spans
5225:
5226: =cut
1.422 foxr 5227:
1.82 albertel 5228: sub get_scantron_config {
5229: my ($which) = @_;
1.518 raeburn 5230: my @lines = &get_scantronformat_file();
1.82 albertel 5231: my %config;
1.157 albertel 5232: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5233: foreach my $line (@lines) {
1.82 albertel 5234: my ($name,$descrip)=split(/:/,$line);
5235: if ($name ne $which ) { next; }
5236: chomp($line);
5237: my @config=split(/:/,$line);
5238: $config{'name'}=$config[0];
5239: $config{'description'}=$config[1];
5240: $config{'CODElocation'}=$config[2];
5241: $config{'CODEstart'}=$config[3];
5242: $config{'CODElength'}=$config[4];
5243: $config{'IDstart'}=$config[5];
5244: $config{'IDlength'}=$config[6];
5245: $config{'Qstart'}=$config[7];
1.497 foxr 5246: $config{'Qlength'}=$config[8];
1.82 albertel 5247: $config{'Qoff'}=$config[9];
5248: $config{'Qon'}=$config[10];
1.157 albertel 5249: $config{'PaperID'}=$config[11];
5250: $config{'PaperIDlength'}=$config[12];
5251: $config{'FirstName'}=$config[13];
5252: $config{'FirstNamelength'}=$config[14];
5253: $config{'LastName'}=$config[15];
5254: $config{'LastNamelength'}=$config[16];
1.82 albertel 5255: last;
5256: }
5257: return %config;
5258: }
5259:
1.423 albertel 5260: =pod
5261:
5262: =item username_to_idmap
5263:
1.556 ! weissno 5264: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5265: student username:domain.
5266:
5267: Arguments:
5268:
5269: $classlist - reference to the class list hash. This is a hash
5270: keyed by student name:domain whose elements are references
1.424 albertel 5271: to arrays containing various chunks of information
1.423 albertel 5272: about the student. (See loncoursedata for more info).
5273:
5274: Returns
5275: %idmap - the constructed hash
5276:
5277: =cut
5278:
1.82 albertel 5279: sub username_to_idmap {
5280: my ($classlist)= @_;
5281: my %idmap;
5282: foreach my $student (keys(%$classlist)) {
5283: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5284: $student;
5285: }
5286: return %idmap;
5287: }
1.423 albertel 5288:
5289: =pod
5290:
1.424 albertel 5291: =item scantron_fixup_scanline
1.423 albertel 5292:
5293: Process a requested correction to a scanline.
5294:
5295: Arguments:
5296: $scantron_config - hash from &get_scantron_config()
5297: $scan_data - hash of correction information
5298: (see &scantron_getfile())
5299: $line - existing scanline
5300: $whichline - line number of the passed in scanline
5301: $field - type of change to process
5302: (either
1.556 ! weissno 5303: 'ID' -> correct the student/employee ID number
1.423 albertel 5304: 'CODE' -> correct the CODE
5305: 'answer' -> fixup the submitted answers)
5306:
5307: $args - hash of additional info,
5308: - 'ID'
5309: 'newid' -> studentID to use in replacement
1.424 albertel 5310: of existing one
1.423 albertel 5311: - 'CODE'
5312: 'CODE_ignore_dup' - set to true if duplicates
5313: should be ignored.
5314: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5315: if the existing unfound code should
1.423 albertel 5316: be used as is
5317: - 'answer'
5318: 'response' - new answer or 'none' if blank
5319: 'question' - the bubble line to change
1.503 raeburn 5320: 'questionnum' - the question identifier,
5321: may include subquestion.
1.423 albertel 5322:
5323: Returns:
5324: $line - the modified scanline
5325:
5326: Side effects:
5327: $scan_data - may be updated
5328:
5329: =cut
5330:
1.82 albertel 5331:
1.157 albertel 5332: sub scantron_fixup_scanline {
5333: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5334: if ($field eq 'ID') {
5335: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5336: return ($line,1,'New value too large');
1.157 albertel 5337: }
5338: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5339: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5340: $args->{'newid'});
5341: }
5342: substr($line,$$scantron_config{'IDstart'}-1,
5343: $$scantron_config{'IDlength'})=$args->{'newid'};
5344: if ($args->{'newid'}=~/^\s*$/) {
5345: &scan_data($scan_data,"$whichline.user",
5346: $args->{'username'}.':'.$args->{'domain'});
5347: }
1.186 albertel 5348: } elsif ($field eq 'CODE') {
1.192 albertel 5349: if ($args->{'CODE_ignore_dup'}) {
5350: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5351: }
5352: &scan_data($scan_data,"$whichline.useCODE",'1');
5353: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5354: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5355: return ($line,1,'New CODE value too large');
5356: }
5357: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5358: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5359: }
5360: substr($line,$$scantron_config{'CODEstart'}-1,
5361: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5362: }
1.157 albertel 5363: } elsif ($field eq 'answer') {
1.497 foxr 5364: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5365: my $off=$scantron_config->{'Qoff'};
5366: my $on=$scantron_config->{'Qon'};
1.497 foxr 5367: my $answer=${off}x$length;
5368: if ($args->{'response'} eq 'none') {
5369: &scan_data($scan_data,
1.503 raeburn 5370: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5371: } else {
5372: if ($on eq 'letter') {
5373: my @alphabet=('A'..'Z');
5374: $answer=$alphabet[$args->{'response'}];
5375: } elsif ($on eq 'number') {
5376: $answer=$args->{'response'}+1;
5377: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5378: } else {
1.497 foxr 5379: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5380: }
1.497 foxr 5381: &scan_data($scan_data,
1.503 raeburn 5382: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5383: }
1.497 foxr 5384: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5385: substr($line,$where-1,$length)=$answer;
1.157 albertel 5386: }
5387: return $line;
5388: }
1.423 albertel 5389:
5390: =pod
5391:
5392: =item scan_data
5393:
5394: Edit or look up an item in the scan_data hash.
5395:
5396: Arguments:
5397: $scan_data - The hash (see scantron_getfile)
5398: $key - shorthand of the key to edit (actual key is
1.424 albertel 5399: scantronfilename_key).
1.423 albertel 5400: $data - New value of the hash entry.
5401: $delete - If true, the entry is removed from the hash.
5402:
5403: Returns:
5404: The new value of the hash table field (undefined if deleted).
5405:
5406: =cut
5407:
5408:
1.157 albertel 5409: sub scan_data {
5410: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5411: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5412: if (defined($value)) {
5413: $scan_data->{$filename.'_'.$key} = $value;
5414: }
5415: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5416: return $scan_data->{$filename.'_'.$key};
5417: }
1.423 albertel 5418:
1.495 albertel 5419: # ----- These first few routines are general use routines.----
5420:
5421: # Return the number of occurences of a pattern in a string.
5422:
5423: sub occurence_count {
5424: my ($string, $pattern) = @_;
5425:
5426: my @matches = ($string =~ /$pattern/g);
5427:
5428: return scalar(@matches);
5429: }
5430:
5431:
5432: # Take a string known to have digits and convert all the
5433: # digits into letters in the range J,A..I.
5434:
5435: sub digits_to_letters {
5436: my ($input) = @_;
5437:
5438: my @alphabet = ('J', 'A'..'I');
5439:
5440: my @input = split(//, $input);
5441: my $output ='';
5442: for (my $i = 0; $i < scalar(@input); $i++) {
5443: if ($input[$i] =~ /\d/) {
5444: $output .= $alphabet[$input[$i]];
5445: } else {
5446: $output .= $input[$i];
5447: }
5448: }
5449: return $output;
5450: }
5451:
1.423 albertel 5452: =pod
5453:
5454: =item scantron_parse_scanline
5455:
5456: Decodes a scanline from the selected scantron file
5457:
5458: Arguments:
5459: line - The text of the scantron file line to process
5460: whichline - Line number
5461: scantron_config - Hash describing the format of the scantron lines.
5462: scan_data - Hash of extra information about the scanline
5463: (see scantron_getfile for more information)
5464: just_header - True if should not process question answers but only
5465: the stuff to the left of the answers.
5466: Returns:
5467: Hash containing the result of parsing the scanline
5468:
5469: Keys are all proceeded by the string 'scantron.'
5470:
5471: CODE - the CODE in use for this scanline
5472: useCODE - 1 if the CODE is invalid but it usage has been forced
5473: by the operator
5474: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5475: CODEs were selected, but the usage has been
5476: forced by the operator
1.556 ! weissno 5477: ID - student/employee ID
1.423 albertel 5478: PaperID - if used, the ID number printed on the sheet when the
5479: paper was scanned
5480: FirstName - first name from the sheet
5481: LastName - last name from the sheet
5482:
5483: if just_header was not true these key may also exist
5484:
1.447 foxr 5485: missingerror - a list of bubble ranges that are considered to be answers
5486: to a single question that don't have any bubbles filled in.
5487: Of the form questionnumber:firstbubblenumber:count.
5488: doubleerror - a list of bubble ranges that are considered to be answers
5489: to a single question that have more than one bubble filled in.
5490: Of the form questionnumber::firstbubblenumber:count
5491:
5492: In the above, count is the number of bubble responses in the
5493: input line needed to represent the possible answers to the question.
5494: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5495: per line would have count = 2.
5496:
1.423 albertel 5497: maxquest - the number of the last bubble line that was parsed
5498:
5499: (<number> starts at 1)
5500: <number>.answer - zero or more letters representing the selected
5501: letters from the scanline for the bubble line
5502: <number>.
5503: if blank there was either no bubble or there where
5504: multiple bubbles, (consult the keys missingerror and
5505: doubleerror if this is an error condition)
5506:
5507: =cut
5508:
1.82 albertel 5509: sub scantron_parse_scanline {
1.423 albertel 5510: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5511:
1.82 albertel 5512: my %record;
1.550 raeburn 5513: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5514: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5515: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5516: if (!($$scantron_config{'CODElocation'} eq 0 ||
5517: $$scantron_config{'CODElocation'} eq 'none')) {
5518: if ($$scantron_config{'CODElocation'} < 0 ||
5519: $$scantron_config{'CODElocation'} eq 'letter' ||
5520: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5521: $record{'scantron.CODE'}=substr($data,
5522: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5523: $$scantron_config{'CODElength'});
1.191 albertel 5524: if (&scan_data($scan_data,"$whichline.useCODE")) {
5525: $record{'scantron.useCODE'}=1;
5526: }
1.192 albertel 5527: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5528: $record{'scantron.CODE_ignore_dup'}=1;
5529: }
1.82 albertel 5530: } else {
5531: #FIXME interpret first N questions
5532: }
5533: }
1.83 albertel 5534: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5535: $$scantron_config{'IDlength'});
1.157 albertel 5536: $record{'scantron.PaperID'}=
5537: substr($data,$$scantron_config{'PaperID'}-1,
5538: $$scantron_config{'PaperIDlength'});
5539: $record{'scantron.FirstName'}=
5540: substr($data,$$scantron_config{'FirstName'}-1,
5541: $$scantron_config{'FirstNamelength'});
5542: $record{'scantron.LastName'}=
5543: substr($data,$$scantron_config{'LastName'}-1,
5544: $$scantron_config{'LastNamelength'});
1.423 albertel 5545: if ($just_header) { return \%record; }
1.194 albertel 5546:
1.82 albertel 5547: my @alphabet=('A'..'Z');
5548: my $questnum=0;
1.447 foxr 5549: my $ansnum =1; # Multiple 'answer lines'/question.
5550:
1.470 foxr 5551: chomp($questions); # Get rid of any trailing \n.
5552: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5553: while (length($questions)) {
1.447 foxr 5554: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5555: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5556: || 1;
5557: $questnum++;
5558: my $quest_id = $questnum;
5559: my $currentquest = substr($questions,0,$answer_length);
5560: $questions = substr($questions,$answer_length);
5561: if (length($currentquest) < $answer_length) { next; }
5562:
5563: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5564: my $subquestnum = 1;
5565: my $subquestions = $currentquest;
5566: my @subanswers_needed =
5567: split(/,/,$subdivided_bubble_lines{$questnum-1});
5568: foreach my $subans (@subanswers_needed) {
5569: my $subans_length =
5570: ($$scantron_config{'Qlength'} * $subans) || 1;
5571: my $currsubquest = substr($subquestions,0,$subans_length);
5572: $subquestions = substr($subquestions,$subans_length);
5573: $quest_id = "$questnum.$subquestnum";
5574: if (($$scantron_config{'Qon'} eq 'letter') ||
5575: ($$scantron_config{'Qon'} eq 'number')) {
5576: $ansnum = &scantron_validator_lettnum($ansnum,
5577: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5578: \@alphabet,\%record,$scantron_config,$scan_data);
5579: } else {
5580: $ansnum = &scantron_validator_positional($ansnum,
5581: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5582: }
5583: $subquestnum ++;
5584: }
5585: } else {
5586: if (($$scantron_config{'Qon'} eq 'letter') ||
5587: ($$scantron_config{'Qon'} eq 'number')) {
5588: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5589: $quest_id,$answers_needed,$currentquest,$whichline,
5590: \@alphabet,\%record,$scantron_config,$scan_data);
5591: } else {
5592: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5593: $quest_id,$answers_needed,$currentquest,$whichline,
5594: \@alphabet,\%record,$scantron_config,$scan_data);
5595: }
5596: }
5597: }
5598: $record{'scantron.maxquest'}=$questnum;
5599: return \%record;
5600: }
1.447 foxr 5601:
1.503 raeburn 5602: sub scantron_validator_lettnum {
5603: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5604: $alphabet,$record,$scantron_config,$scan_data) = @_;
5605:
5606: # Qon 'letter' implies for each slot in currquest we have:
5607: # ? or * for doubles, a letter in A-Z for a bubble, and
5608: # about anything else (esp. a value of Qoff) for missing
5609: # bubbles.
5610: #
5611: # Qon 'number' implies each slot gives a digit that indexes the
5612: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5613: # and * or ? for double bubbles on a single line.
5614: #
1.447 foxr 5615:
1.503 raeburn 5616: my $matchon;
5617: if ($$scantron_config{'Qon'} eq 'letter') {
5618: $matchon = '[A-Z]';
5619: } elsif ($$scantron_config{'Qon'} eq 'number') {
5620: $matchon = '\d';
5621: }
5622: my $occurrences = 0;
5623: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5624: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5625: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5626: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5627: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5628: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5629: my @singlelines = split('',$currquest);
5630: foreach my $entry (@singlelines) {
5631: $occurrences = &occurence_count($entry,$matchon);
5632: if ($occurrences > 1) {
5633: last;
5634: }
5635: }
5636: } else {
5637: $occurrences = &occurence_count($currquest,$matchon);
5638: }
5639: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5640: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5641: for (my $ans=0; $ans<$answers_needed; $ans++) {
5642: my $bubble = substr($currquest,$ans,1);
5643: if ($bubble =~ /$matchon/ ) {
5644: if ($$scantron_config{'Qon'} eq 'number') {
5645: if ($bubble == 0) {
5646: $bubble = 10;
5647: }
5648: $record->{"scantron.$ansnum.answer"} =
5649: $alphabet->[$bubble-1];
5650: } else {
5651: $record->{"scantron.$ansnum.answer"} = $bubble;
5652: }
5653: } else {
5654: $record->{"scantron.$ansnum.answer"}='';
5655: }
5656: $ansnum++;
5657: }
5658: } elsif (!defined($currquest)
5659: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5660: || (&occurence_count($currquest,$matchon) == 0)) {
5661: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5662: $record->{"scantron.$ansnum.answer"}='';
5663: $ansnum++;
5664: }
5665: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5666: push(@{$record->{'scantron.missingerror'}},$quest_id);
5667: }
5668: } else {
5669: if ($$scantron_config{'Qon'} eq 'number') {
5670: $currquest = &digits_to_letters($currquest);
5671: }
5672: for (my $ans=0; $ans<$answers_needed; $ans++) {
5673: my $bubble = substr($currquest,$ans,1);
5674: $record->{"scantron.$ansnum.answer"} = $bubble;
5675: $ansnum++;
5676: }
5677: }
5678: return $ansnum;
5679: }
1.447 foxr 5680:
1.503 raeburn 5681: sub scantron_validator_positional {
5682: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5683: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5684:
1.503 raeburn 5685: # Otherwise there's a positional notation;
5686: # each bubble line requires Qlength items, and there are filled in
5687: # bubbles for each case where there 'Qon' characters.
5688: #
1.447 foxr 5689:
1.503 raeburn 5690: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5691:
1.503 raeburn 5692: # If the split only gives us one element.. the full length of the
5693: # answer string, no bubbles are filled in:
1.447 foxr 5694:
1.507 raeburn 5695: if ($answers_needed eq '') {
5696: return;
5697: }
5698:
1.503 raeburn 5699: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5700: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5701: $record->{"scantron.$ansnum.answer"}='';
5702: $ansnum++;
5703: }
5704: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5705: push(@{$record->{"scantron.missingerror"}},$quest_id);
5706: }
5707: } elsif (scalar(@array) == 2) {
5708: my $location = length($array[0]);
5709: my $line_num = int($location / $$scantron_config{'Qlength'});
5710: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5711: for (my $ans=0; $ans<$answers_needed; $ans++) {
5712: if ($ans eq $line_num) {
5713: $record->{"scantron.$ansnum.answer"} = $bubble;
5714: } else {
5715: $record->{"scantron.$ansnum.answer"} = ' ';
5716: }
5717: $ansnum++;
5718: }
5719: } else {
5720: # If there's more than one instance of a bubble character
5721: # That's a double bubble; with positional notation we can
5722: # record all the bubbles filled in as well as the
5723: # fact this response consists of multiple bubbles.
5724: #
5725: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5726: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5727: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5728: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5729: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5730: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5731: my $doubleerror = 0;
5732: while (($currquest >= $$scantron_config{'Qlength'}) &&
5733: (!$doubleerror)) {
5734: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5735: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5736: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5737: if (length(@currarray) > 2) {
5738: $doubleerror = 1;
5739: }
5740: }
5741: if ($doubleerror) {
5742: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5743: }
5744: } else {
5745: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5746: }
5747: my $item = $ansnum;
5748: for (my $ans=0; $ans<$answers_needed; $ans++) {
5749: $record->{"scantron.$item.answer"} = '';
5750: $item ++;
5751: }
1.447 foxr 5752:
1.503 raeburn 5753: my @ans=@array;
5754: my $i=0;
5755: my $increment = 0;
5756: while ($#ans) {
5757: $i+=length($ans[0]) + $increment;
5758: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5759: my $bubble = $i%$$scantron_config{'Qlength'};
5760: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5761: shift(@ans);
5762: $increment = 1;
5763: }
5764: $ansnum += $answers_needed;
1.82 albertel 5765: }
1.503 raeburn 5766: return $ansnum;
1.82 albertel 5767: }
5768:
1.423 albertel 5769: =pod
5770:
5771: =item scantron_add_delay
5772:
5773: Adds an error message that occurred during the grading phase to a
5774: queue of messages to be shown after grading pass is complete
5775:
5776: Arguments:
1.424 albertel 5777: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5778: $scanline - the scanline that caused the error
5779: $errormesage - the error message
5780: $errorcode - a numeric code for the error
5781:
5782: Side Effects:
1.424 albertel 5783: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5784:
5785: =cut
5786:
1.82 albertel 5787: sub scantron_add_delay {
1.140 albertel 5788: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5789: push(@$delayqueue,
5790: {'line' => $scanline, 'emsg' => $errormessage,
5791: 'ecode' => $errorcode }
5792: );
1.82 albertel 5793: }
5794:
1.423 albertel 5795: =pod
5796:
5797: =item scantron_find_student
5798:
1.424 albertel 5799: Finds the username for the current scanline
5800:
5801: Arguments:
5802: $scantron_record - hash result from scantron_parse_scanline
5803: $scan_data - hash of correction information
5804: (see &scantron_getfile() form more information)
5805: $idmap - hash from &username_to_idmap()
5806: $line - number of current scanline
5807:
5808: Returns:
5809: Either 'username:domain' or undef if unknown
5810:
1.423 albertel 5811: =cut
5812:
1.82 albertel 5813: sub scantron_find_student {
1.157 albertel 5814: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5815: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5816: if ($scanID =~ /^\s*$/) {
5817: return &scan_data($scan_data,"$line.user");
5818: }
1.83 albertel 5819: foreach my $id (keys(%$idmap)) {
1.157 albertel 5820: if (lc($id) eq lc($scanID)) {
5821: return $$idmap{$id};
5822: }
1.83 albertel 5823: }
5824: return undef;
5825: }
5826:
1.423 albertel 5827: =pod
5828:
5829: =item scantron_filter
5830:
1.424 albertel 5831: Filter sub for lonnavmaps, filters out hidden resources if ignore
5832: hidden resources was selected
5833:
1.423 albertel 5834: =cut
5835:
1.83 albertel 5836: sub scantron_filter {
5837: my ($curres)=@_;
1.331 albertel 5838:
5839: if (ref($curres) && $curres->is_problem()) {
5840: # if the user has asked to not have either hidden
5841: # or 'randomout' controlled resources to be graded
5842: # don't include them
5843: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5844: && $curres->randomout) {
5845: return 0;
5846: }
1.83 albertel 5847: return 1;
5848: }
5849: return 0;
1.82 albertel 5850: }
5851:
1.423 albertel 5852: =pod
5853:
5854: =item scantron_process_corrections
5855:
1.424 albertel 5856: Gets correction information out of submitted form data and corrects
5857: the scanline
5858:
1.423 albertel 5859: =cut
5860:
1.157 albertel 5861: sub scantron_process_corrections {
5862: my ($r) = @_;
1.257 albertel 5863: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5864: my ($scanlines,$scan_data)=&scantron_getfile();
5865: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5866: my $which=$env{'form.scantron_line'};
1.200 albertel 5867: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5868: my ($skip,$err,$errmsg);
1.257 albertel 5869: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5870: $skip=1;
1.257 albertel 5871: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5872: my $newstudent=$env{'form.scantron_username'}.':'.
5873: $env{'form.scantron_domain'};
1.157 albertel 5874: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5875: ($line,$err,$errmsg)=
5876: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5877: 'ID',{'newid'=>$newid,
1.257 albertel 5878: 'username'=>$env{'form.scantron_username'},
5879: 'domain'=>$env{'form.scantron_domain'}});
5880: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5881: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5882: my $newCODE;
1.192 albertel 5883: my %args;
1.190 albertel 5884: if ($resolution eq 'use_unfound') {
1.191 albertel 5885: $newCODE='use_unfound';
1.190 albertel 5886: } elsif ($resolution eq 'use_found') {
1.257 albertel 5887: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 5888: } elsif ($resolution eq 'use_typed') {
1.257 albertel 5889: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 5890: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 5891: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 5892: }
1.257 albertel 5893: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 5894: $args{'CODE_ignore_dup'}=1;
5895: }
5896: $args{'CODE'}=$newCODE;
1.186 albertel 5897: ($line,$err,$errmsg)=
5898: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 5899: 'CODE',\%args);
1.257 albertel 5900: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
5901: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 5902: ($line,$err,$errmsg)=
5903: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
5904: $which,'answer',
5905: { 'question'=>$question,
1.503 raeburn 5906: 'response'=>$env{"form.scantron_correct_Q_$question"},
5907: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 5908: if ($err) { last; }
5909: }
5910: }
5911: if ($err) {
1.398 albertel 5912: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 5913: } else {
1.200 albertel 5914: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 5915: &scantron_putfile($scanlines,$scan_data);
5916: }
5917: }
5918:
1.423 albertel 5919: =pod
5920:
5921: =item reset_skipping_status
5922:
1.424 albertel 5923: Forgets the current set of remember skipped scanlines (and thus
5924: reverts back to considering all lines in the
5925: scantron_skipped_<filename> file)
5926:
1.423 albertel 5927: =cut
5928:
1.200 albertel 5929: sub reset_skipping_status {
5930: my ($scanlines,$scan_data)=&scantron_getfile();
5931: &scan_data($scan_data,'remember_skipping',undef,1);
5932: &scantron_putfile(undef,$scan_data);
5933: }
5934:
1.423 albertel 5935: =pod
5936:
5937: =item start_skipping
5938:
1.424 albertel 5939: Marks a scanline to be skipped.
5940:
1.423 albertel 5941: =cut
5942:
1.376 albertel 5943: sub start_skipping {
1.200 albertel 5944: my ($scan_data,$i)=@_;
5945: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5946: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
5947: $remembered{$i}=2;
5948: } else {
5949: $remembered{$i}=1;
5950: }
1.200 albertel 5951: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
5952: }
5953:
1.423 albertel 5954: =pod
5955:
5956: =item should_be_skipped
5957:
1.424 albertel 5958: Checks whether a scanline should be skipped.
5959:
1.423 albertel 5960: =cut
5961:
1.200 albertel 5962: sub should_be_skipped {
1.376 albertel 5963: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 5964: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 5965: # not redoing old skips
1.376 albertel 5966: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 5967: return 0;
5968: }
5969: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5970:
5971: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
5972: return 0;
5973: }
1.200 albertel 5974: return 1;
5975: }
5976:
1.423 albertel 5977: =pod
5978:
5979: =item remember_current_skipped
5980:
1.424 albertel 5981: Discovers what scanlines are in the scantron_skipped_<filename>
5982: file and remembers them into scan_data for later use.
5983:
1.423 albertel 5984: =cut
5985:
1.200 albertel 5986: sub remember_current_skipped {
5987: my ($scanlines,$scan_data)=&scantron_getfile();
5988: my %to_remember;
5989: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5990: if ($scanlines->{'skipped'}[$i]) {
5991: $to_remember{$i}=1;
5992: }
5993: }
1.376 albertel 5994:
1.200 albertel 5995: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
5996: &scantron_putfile(undef,$scan_data);
5997: }
5998:
1.423 albertel 5999: =pod
6000:
6001: =item check_for_error
6002:
1.424 albertel 6003: Checks if there was an error when attempting to remove a specific
6004: scantron_.. bubble sheet data file. Prints out an error if
6005: something went wrong.
6006:
1.423 albertel 6007: =cut
6008:
1.200 albertel 6009: sub check_for_error {
6010: my ($r,$result)=@_;
6011: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6012: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6013: }
6014: }
1.157 albertel 6015:
1.423 albertel 6016: =pod
6017:
6018: =item scantron_warning_screen
6019:
1.424 albertel 6020: Interstitial screen to make sure the operator has selected the
6021: correct options before we start the validation phase.
6022:
1.423 albertel 6023: =cut
6024:
1.203 albertel 6025: sub scantron_warning_screen {
6026: my ($button_text)=@_;
1.257 albertel 6027: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6028: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6029: my $CODElist;
1.284 albertel 6030: if ($scantron_config{'CODElocation'} &&
6031: $scantron_config{'CODEstart'} &&
6032: $scantron_config{'CODElength'}) {
6033: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6034: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6035: $CODElist=
1.492 albertel 6036: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6037: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6038: }
1.492 albertel 6039: return ('
1.203 albertel 6040: <p>
1.492 albertel 6041: <span class="LC_warning">
6042: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6043: </p>
6044: <table>
1.492 albertel 6045: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6046: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6047: '.$CODElist.'
1.203 albertel 6048: </table>
6049: <br />
1.492 albertel 6050: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6051: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6052:
6053: <br />
1.492 albertel 6054: ');
1.203 albertel 6055: }
6056:
1.423 albertel 6057: =pod
6058:
6059: =item scantron_do_warning
6060:
1.424 albertel 6061: Check if the operator has picked something for all required
6062: fields. Error out if something is missing.
6063:
1.423 albertel 6064: =cut
6065:
1.203 albertel 6066: sub scantron_do_warning {
6067: my ($r)=@_;
1.324 albertel 6068: my ($symb)=&get_symb($r);
1.203 albertel 6069: if (!$symb) {return '';}
1.324 albertel 6070: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6071: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6072: if ( $env{'form.selectpage'} eq '' ||
6073: $env{'form.scantron_selectfile'} eq '' ||
6074: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6075: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6076: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6077: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6078: }
1.257 albertel 6079: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6080: $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 6081: }
1.257 albertel 6082: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6083: $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 6084: }
6085: } else {
1.265 www 6086: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6087: $r->print('
6088: '.$warning.'
6089: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6090: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6091: ');
1.237 albertel 6092: }
1.352 albertel 6093: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6094: return '';
6095: }
6096:
1.423 albertel 6097: =pod
6098:
6099: =item scantron_form_start
6100:
1.424 albertel 6101: html hidden input for remembering all selected grading options
6102:
1.423 albertel 6103: =cut
6104:
1.203 albertel 6105: sub scantron_form_start {
6106: my ($max_bubble)=@_;
6107: my $result= <<SCANTRONFORM;
6108: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6109: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6110: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6111: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6112: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6113: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6114: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6115: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6116: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6117: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6118: SCANTRONFORM
1.447 foxr 6119:
6120: my $line = 0;
6121: while (defined($env{"form.scantron.bubblelines.$line"})) {
6122: my $chunk =
6123: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6124: $chunk .=
6125: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6126: $chunk .=
6127: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6128: $chunk .=
6129: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6130: $result .= $chunk;
6131: $line++;
6132: }
1.203 albertel 6133: return $result;
6134: }
6135:
1.423 albertel 6136: =pod
6137:
6138: =item scantron_validate_file
6139:
1.424 albertel 6140: Dispatch routine for doing validation of a bubble sheet data file.
6141:
6142: Also processes any necessary information resets that need to
6143: occur before validation begins (ignore previous corrections,
6144: restarting the skipped records processing)
6145:
1.423 albertel 6146: =cut
6147:
1.157 albertel 6148: sub scantron_validate_file {
6149: my ($r) = @_;
1.324 albertel 6150: my ($symb)=&get_symb($r);
1.157 albertel 6151: if (!$symb) {return '';}
1.324 albertel 6152: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6153:
6154: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6155: # them when doing the corrections reset
1.257 albertel 6156: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6157: &reset_skipping_status();
6158: }
1.257 albertel 6159: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6160: &remember_current_skipped();
1.257 albertel 6161: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6162: }
6163:
1.257 albertel 6164: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6165: &check_for_error($r,&scantron_remove_file('corrected'));
6166: &check_for_error($r,&scantron_remove_file('skipped'));
6167: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6168: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6169: }
1.200 albertel 6170:
1.257 albertel 6171: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6172: &scantron_process_corrections($r);
6173: }
1.503 raeburn 6174: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6175: #get the student pick code ready
6176: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 6177: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 6178: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6179: $r->print($result);
6180:
1.334 albertel 6181: my @validate_phases=( 'sequence',
6182: 'ID',
1.157 albertel 6183: 'CODE',
6184: 'doublebubble',
6185: 'missingbubbles');
1.257 albertel 6186: if (!$env{'form.validatepass'}) {
6187: $env{'form.validatepass'} = 0;
1.157 albertel 6188: }
1.257 albertel 6189: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6190:
1.448 foxr 6191:
1.157 albertel 6192: my $stop=0;
6193: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6194: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6195: $r->rflush();
6196: my $which="scantron_validate_".$validate_phases[$currentphase];
6197: {
6198: no strict 'refs';
6199: ($stop,$currentphase)=&$which($r,$currentphase);
6200: }
6201: }
6202: if (!$stop) {
1.203 albertel 6203: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6204: $r->print(&mt('Validation process complete.').'<br />'.
6205: $warning.
6206: &mt('Perform verification for each student after storage of submissions?').
6207: ' <span class="LC_nobreak"><label>'.
6208: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6209: (' 'x3).'<label>'.
6210: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6211: '</label></span><br />'.
6212: &mt('Grading will take longer if you use verification.').'<br />'.
6213: &mt("Alternatively, the 'Review scantron data' utility (see grading menu) can be used for all students after grading is complete.").'<br /><br />'.
6214: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6215: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6216: } else {
6217: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6218: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6219: }
6220: if ($stop) {
1.334 albertel 6221: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6222: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6223: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6224:
1.492 albertel 6225: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6226: } else {
1.503 raeburn 6227: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6228: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6229: } else {
1.539 riegler 6230: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6231: }
1.492 albertel 6232: $r->print(' '.&mt('using corrected info').' <br />');
6233: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6234: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6235: }
1.157 albertel 6236: }
1.352 albertel 6237: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6238: return '';
6239: }
6240:
1.423 albertel 6241:
6242: =pod
6243:
6244: =item scantron_remove_file
6245:
1.424 albertel 6246: Removes the requested bubble sheet data file, makes sure that
6247: scantron_original_<filename> is never removed
6248:
6249:
1.423 albertel 6250: =cut
6251:
1.200 albertel 6252: sub scantron_remove_file {
1.192 albertel 6253: my ($which)=@_;
1.257 albertel 6254: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6255: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6256: my $file='scantron_';
1.200 albertel 6257: if ($which eq 'corrected' || $which eq 'skipped') {
6258: $file.=$which.'_';
1.192 albertel 6259: } else {
6260: return 'refused';
6261: }
1.257 albertel 6262: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6263: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6264: }
6265:
1.423 albertel 6266:
6267: =pod
6268:
6269: =item scantron_remove_scan_data
6270:
1.424 albertel 6271: Removes all scan_data correction for the requested bubble sheet
6272: data file. (In the case that both the are doing skipped records we need
6273: to remember the old skipped lines for the time being so that element
6274: persists for a while.)
6275:
1.423 albertel 6276: =cut
6277:
1.200 albertel 6278: sub scantron_remove_scan_data {
1.257 albertel 6279: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6280: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6281: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6282: my @todelete;
1.257 albertel 6283: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6284: foreach my $key (@keys) {
6285: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6286: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6287: $key=~/remember_skipping/) {
6288: next;
6289: }
1.192 albertel 6290: push(@todelete,$key);
6291: }
6292: }
1.200 albertel 6293: my $result;
1.192 albertel 6294: if (@todelete) {
1.491 albertel 6295: $result = &Apache::lonnet::del('nohist_scantrondata',
6296: \@todelete,$cdom,$cname);
6297: } else {
6298: $result = 'ok';
1.192 albertel 6299: }
6300: return $result;
6301: }
6302:
1.423 albertel 6303:
6304: =pod
6305:
6306: =item scantron_getfile
6307:
1.424 albertel 6308: Fetches the requested bubble sheet data file (all 3 versions), and
6309: the scan_data hash
6310:
6311: Arguments:
6312: None
6313:
6314: Returns:
6315: 2 hash references
6316:
6317: - first one has
6318: orig -
6319: corrected -
6320: skipped - each of which points to an array ref of the specified
6321: file broken up into individual lines
6322: count - number of scanlines
6323:
6324: - second is the scan_data hash possible keys are
1.425 albertel 6325: ($number refers to scanline numbered $number and thus the key affects
6326: only that scanline
6327: $bubline refers to the specific bubble line element and the aspects
6328: refers to that specific bubble line element)
6329:
6330: $number.user - username:domain to use
6331: $number.CODE_ignore_dup
6332: - ignore the duplicate CODE error
6333: $number.useCODE
6334: - use the CODE in the scanline as is
6335: $number.no_bubble.$bubline
6336: - it is valid that there is no bubbled in bubble
6337: at $number $bubline
6338: remember_skipping
6339: - a frozen hash containing keys of $number and values
6340: of either
6341: 1 - we are on a 'do skipped records pass' and plan
6342: on processing this line
6343: 2 - we are on a 'do skipped records pass' and this
6344: scanline has been marked to skip yet again
1.424 albertel 6345:
1.423 albertel 6346: =cut
6347:
1.157 albertel 6348: sub scantron_getfile {
1.200 albertel 6349: #FIXME really would prefer a scantron directory
1.257 albertel 6350: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6351: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6352: my $lines;
6353: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6354: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6355: my %scanlines;
6356: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6357: my $temp=$scanlines{'orig'};
6358: $scanlines{'count'}=$#$temp;
6359:
6360: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6361: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6362: if ($lines eq '-1') {
6363: $scanlines{'corrected'}=[];
6364: } else {
6365: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6366: }
6367: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6368: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6369: if ($lines eq '-1') {
6370: $scanlines{'skipped'}=[];
6371: } else {
6372: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6373: }
1.175 albertel 6374: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6375: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6376: my %scan_data = @tmp;
6377: return (\%scanlines,\%scan_data);
6378: }
6379:
1.423 albertel 6380: =pod
6381:
6382: =item lonnet_putfile
6383:
1.424 albertel 6384: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6385:
6386: Arguments:
6387: $contents - data to store
6388: $filename - filename to store $contents into
6389:
6390: Returns:
6391: result value from &Apache::lonnet::finishuserfileupload
6392:
1.423 albertel 6393: =cut
6394:
1.157 albertel 6395: sub lonnet_putfile {
6396: my ($contents,$filename)=@_;
1.257 albertel 6397: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6398: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6399: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6400: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6401:
6402: }
6403:
1.423 albertel 6404: =pod
6405:
6406: =item scantron_putfile
6407:
1.424 albertel 6408: Stores the current version of the bubble sheet data files, and the
6409: scan_data hash. (Does not modify the original version only the
6410: corrected and skipped versions.
6411:
6412: Arguments:
6413: $scanlines - hash ref that looks like the first return value from
6414: &scantron_getfile()
6415: $scan_data - hash ref that looks like the second return value from
6416: &scantron_getfile()
6417:
1.423 albertel 6418: =cut
6419:
1.157 albertel 6420: sub scantron_putfile {
6421: my ($scanlines,$scan_data) = @_;
1.200 albertel 6422: #FIXME really would prefer a scantron directory
1.257 albertel 6423: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6424: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6425: if ($scanlines) {
6426: my $prefix='scantron_';
1.157 albertel 6427: # no need to update orig, shouldn't change
6428: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6429: # $env{'form.scantron_selectfile'});
1.200 albertel 6430: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6431: $prefix.'corrected_'.
1.257 albertel 6432: $env{'form.scantron_selectfile'});
1.200 albertel 6433: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6434: $prefix.'skipped_'.
1.257 albertel 6435: $env{'form.scantron_selectfile'});
1.200 albertel 6436: }
1.175 albertel 6437: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6438: }
6439:
1.423 albertel 6440: =pod
6441:
6442: =item scantron_get_line
6443:
1.424 albertel 6444: Returns the correct version of the scanline
6445:
6446: Arguments:
6447: $scanlines - hash ref that looks like the first return value from
6448: &scantron_getfile()
6449: $scan_data - hash ref that looks like the second return value from
6450: &scantron_getfile()
6451: $i - number of the requested line (starts at 0)
6452:
6453: Returns:
6454: A scanline, (either the original or the corrected one if it
6455: exists), or undef if the requested scanline should be
6456: skipped. (Either because it's an skipped scanline, or it's an
6457: unskipped scanline and we are not doing a 'do skipped scanlines'
6458: pass.
6459:
1.423 albertel 6460: =cut
6461:
1.157 albertel 6462: sub scantron_get_line {
1.200 albertel 6463: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6464: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6465: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6466: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6467: return $scanlines->{'orig'}[$i];
6468: }
6469:
1.423 albertel 6470: =pod
6471:
6472: =item scantron_todo_count
6473:
1.424 albertel 6474: Counts the number of scanlines that need processing.
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:
6482: Returns:
6483: $count - number of scanlines to process
6484:
1.423 albertel 6485: =cut
6486:
1.200 albertel 6487: sub get_todo_count {
6488: my ($scanlines,$scan_data)=@_;
6489: my $count=0;
6490: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6491: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6492: if ($line=~/^[\s\cz]*$/) { next; }
6493: $count++;
6494: }
6495: return $count;
6496: }
6497:
1.423 albertel 6498: =pod
6499:
6500: =item scantron_put_line
6501:
1.424 albertel 6502: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6503: data file.
6504:
6505: Arguments:
6506: $scanlines - hash ref that looks like the first return value from
6507: &scantron_getfile()
6508: $scan_data - hash ref that looks like the second return value from
6509: &scantron_getfile()
6510: $i - line number to update
6511: $newline - contents of the updated scanline
6512: $skip - if true make the line for skipping and update the
6513: 'skipped' file
6514:
1.423 albertel 6515: =cut
6516:
1.157 albertel 6517: sub scantron_put_line {
1.200 albertel 6518: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6519: if ($skip) {
6520: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6521: &start_skipping($scan_data,$i);
1.157 albertel 6522: return;
6523: }
6524: $scanlines->{'corrected'}[$i]=$newline;
6525: }
6526:
1.423 albertel 6527: =pod
6528:
6529: =item scantron_clear_skip
6530:
1.424 albertel 6531: Remove a line from the 'skipped' file
6532:
6533: Arguments:
6534: $scanlines - hash ref that looks like the first return value from
6535: &scantron_getfile()
6536: $scan_data - hash ref that looks like the second return value from
6537: &scantron_getfile()
6538: $i - line number to update
6539:
1.423 albertel 6540: =cut
6541:
1.376 albertel 6542: sub scantron_clear_skip {
6543: my ($scanlines,$scan_data,$i)=@_;
6544: if (exists($scanlines->{'skipped'}[$i])) {
6545: undef($scanlines->{'skipped'}[$i]);
6546: return 1;
6547: }
6548: return 0;
6549: }
6550:
1.423 albertel 6551: =pod
6552:
6553: =item scantron_filter_not_exam
6554:
1.424 albertel 6555: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6556: filter out resources that are not marked as 'exam' mode
6557:
1.423 albertel 6558: =cut
6559:
1.334 albertel 6560: sub scantron_filter_not_exam {
6561: my ($curres)=@_;
6562:
6563: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6564: # if the user has asked to not have either hidden
6565: # or 'randomout' controlled resources to be graded
6566: # don't include them
6567: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6568: && $curres->randomout) {
6569: return 0;
6570: }
6571: return 1;
6572: }
6573: return 0;
6574: }
6575:
1.423 albertel 6576: =pod
6577:
6578: =item scantron_validate_sequence
6579:
1.424 albertel 6580: Validates the selected sequence, checking for resource that are
6581: not set to exam mode.
6582:
1.423 albertel 6583: =cut
6584:
1.334 albertel 6585: sub scantron_validate_sequence {
6586: my ($r,$currentphase) = @_;
6587:
6588: my $navmap=Apache::lonnavmaps::navmap->new();
6589: my (undef,undef,$sequence)=
6590: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6591:
6592: my $map=$navmap->getResourceByUrl($sequence);
6593:
6594: $r->print('<input type="hidden" name="validate_sequence_exam"
6595: value="ignore" />');
6596: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6597: my @resources=
6598: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6599: if (@resources) {
1.357 banghart 6600: $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 6601: return (1,$currentphase);
6602: }
6603: }
6604:
6605: return (0,$currentphase+1);
6606: }
6607:
1.423 albertel 6608:
6609:
1.157 albertel 6610: sub scantron_validate_ID {
6611: my ($r,$currentphase) = @_;
6612:
6613: #get student info
6614: my $classlist=&Apache::loncoursedata::get_classlist();
6615: my %idmap=&username_to_idmap($classlist);
6616:
6617: #get scantron line setup
1.257 albertel 6618: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6619: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 6620:
6621: &scantron_get_maxbubble(); # parse needs the bubble_lines.. array.
1.157 albertel 6622:
6623: my %found=('ids'=>{},'usernames'=>{});
6624: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6625: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6626: if ($line=~/^[\s\cz]*$/) { next; }
6627: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6628: $scan_data);
6629: my $id=$$scan_record{'scantron.ID'};
6630: my $found;
6631: foreach my $checkid (keys(%idmap)) {
6632: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6633: }
6634: if ($found) {
6635: my $username=$idmap{$found};
6636: if ($found{'ids'}{$found}) {
6637: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6638: $line,'duplicateID',$found);
1.194 albertel 6639: return(1,$currentphase);
1.157 albertel 6640: } elsif ($found{'usernames'}{$username}) {
6641: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6642: $line,'duplicateID',$username);
1.194 albertel 6643: return(1,$currentphase);
1.157 albertel 6644: }
1.186 albertel 6645: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6646: $found{'ids'}{$found}++;
6647: $found{'usernames'}{$username}++;
6648: } else {
6649: if ($id =~ /^\s*$/) {
1.158 albertel 6650: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6651: if (defined($username) && $found{'usernames'}{$username}) {
6652: &scantron_get_correction($r,$i,$scan_record,
6653: \%scantron_config,
6654: $line,'duplicateID',$username);
1.194 albertel 6655: return(1,$currentphase);
1.157 albertel 6656: } elsif (!defined($username)) {
6657: &scantron_get_correction($r,$i,$scan_record,
6658: \%scantron_config,
6659: $line,'incorrectID');
1.194 albertel 6660: return(1,$currentphase);
1.157 albertel 6661: }
6662: $found{'usernames'}{$username}++;
6663: } else {
6664: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6665: $line,'incorrectID');
1.194 albertel 6666: return(1,$currentphase);
1.157 albertel 6667: }
6668: }
6669: }
6670:
6671: return (0,$currentphase+1);
6672: }
6673:
1.423 albertel 6674:
1.157 albertel 6675: sub scantron_get_correction {
6676: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6677: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6678: #to show both the current line and the previous one and allow skipping
6679: #the previous one or the current one
6680:
1.333 albertel 6681: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6682: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6683: " for PaperID <tt>[_1]</tt>",
6684: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6685: } else {
1.492 albertel 6686: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6687: " in scanline [_1] <pre>[_2]</pre>",
6688: $i,$line)."</p> \n");
6689: }
6690: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6691: "The name on the paper is [_2],[_3]",
6692: $$scan_record{'scantron.ID'},
6693: $$scan_record{'scantron.LastName'},
6694: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6695:
1.157 albertel 6696: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6697: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6698: # Array populated for doublebubble or
6699: my @lines_to_correct; # missingbubble errors to build javascript
6700: # to validate radio button checking
6701:
1.157 albertel 6702: if ($error =~ /ID$/) {
1.186 albertel 6703: if ($error eq 'incorrectID') {
1.492 albertel 6704: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6705: "</p>\n");
1.157 albertel 6706: } elsif ($error eq 'duplicateID') {
1.492 albertel 6707: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6708: }
1.242 albertel 6709: $r->print($message);
1.492 albertel 6710: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6711: $r->print("\n<ul><li> ");
6712: #FIXME it would be nice if this sent back the user ID and
6713: #could do partial userID matches
6714: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6715: 'scantron_username','scantron_domain'));
6716: $r->print(": <input type='text' name='scantron_username' value='' />");
6717: $r->print("\n@".
1.257 albertel 6718: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6719:
6720: $r->print('</li>');
1.186 albertel 6721: } elsif ($error =~ /CODE$/) {
6722: if ($error eq 'incorrectCODE') {
1.492 albertel 6723: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6724: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6725: $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 6726: }
1.492 albertel 6727: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6728: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6729: $r->print($message);
1.492 albertel 6730: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6731: $r->print("\n<br /> ");
1.194 albertel 6732: my $i=0;
1.273 albertel 6733: if ($error eq 'incorrectCODE'
6734: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6735: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6736: if ($closest > 0) {
6737: foreach my $testcode (@{$closest}) {
6738: my $checked='';
1.401 albertel 6739: if (!$i) { $checked=' checked="checked" '; }
1.492 albertel 6740: $r->print("
6741: <label>
6742: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked />
6743: ".&mt("Use the similar CODE [_1] instead.",
6744: "<b><tt>".$testcode."</tt></b>")."
6745: </label>
6746: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6747: $r->print("\n<br />");
6748: $i++;
6749: }
1.194 albertel 6750: }
6751: }
1.273 albertel 6752: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.401 albertel 6753: my $checked; if (!$i) { $checked=' checked="checked" '; }
1.492 albertel 6754: $r->print("
6755: <label>
6756: <input type='radio' name='scantron_CODE_resolution' value='use_unfound' $checked />
6757: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6758: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6759: </label>");
1.273 albertel 6760: $r->print("\n<br />");
6761: }
1.194 albertel 6762:
1.188 albertel 6763: $r->print(<<ENDSCRIPT);
6764: <script type="text/javascript">
6765: function change_radio(field) {
1.190 albertel 6766: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6767: var i;
6768: for (i=0;i<slct.length;i++) {
6769: if (slct[i].value==field) { slct[i].checked=true; }
6770: }
6771: }
6772: </script>
6773: ENDSCRIPT
1.187 albertel 6774: my $href="/adm/pickcode?".
1.359 www 6775: "form=".&escape("scantronupload").
6776: "&scantron_format=".&escape($env{'form.scantron_format'}).
6777: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6778: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6779: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6780: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6781: $r->print("
6782: <label>
6783: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6784: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6785: "<a target='_blank' href='$href'>","</a>")."
6786: </label>
6787: ".&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 6788: $r->print("\n<br />");
6789: }
1.492 albertel 6790: $r->print("
6791: <label>
6792: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6793: ".&mt("Use [_1] as the CODE.",
6794: "</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 6795: $r->print("\n<br /><br />");
1.157 albertel 6796: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6797: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6798:
6799: # The form field scantron_questions is acutally a list of line numbers.
6800: # represented by this form so:
6801:
6802: my $line_list = &questions_to_line_list($arg);
6803:
1.157 albertel 6804: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6805: $line_list.'" />');
1.242 albertel 6806: $r->print($message);
1.492 albertel 6807: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6808: foreach my $question (@{$arg}) {
1.503 raeburn 6809: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6810: $scan_record, $error);
1.524 raeburn 6811: push(@lines_to_correct,@linenums);
1.157 albertel 6812: }
1.503 raeburn 6813: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6814: } elsif ($error eq 'missingbubble') {
1.492 albertel 6815: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6816: $r->print($message);
1.492 albertel 6817: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 6818: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 6819:
1.503 raeburn 6820: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 6821: # a list of question numbers. Therefore:
6822: #
6823:
6824: my $line_list = &questions_to_line_list($arg);
6825:
1.157 albertel 6826: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6827: $line_list.'" />');
1.157 albertel 6828: foreach my $question (@{$arg}) {
1.503 raeburn 6829: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6830: $scan_record, $error);
1.524 raeburn 6831: push(@lines_to_correct,@linenums);
1.157 albertel 6832: }
1.503 raeburn 6833: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6834: } else {
6835: $r->print("\n<ul>");
6836: }
6837: $r->print("\n</li></ul>");
1.497 foxr 6838: }
6839:
1.503 raeburn 6840: sub verify_bubbles_checked {
6841: my (@ansnums) = @_;
6842: my $ansnumstr = join('","',@ansnums);
6843: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
6844: my $output = (<<ENDSCRIPT);
6845: <script type="text/javascript">
6846: function verify_bubble_radio(form) {
6847: var ansnumArray = new Array ("$ansnumstr");
6848: var need_bubble_count = 0;
6849: for (var i=0; i<ansnumArray.length; i++) {
6850: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
6851: var bubble_picked = 0;
6852: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
6853: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
6854: bubble_picked = 1;
6855: }
6856: }
6857: if (bubble_picked == 0) {
6858: need_bubble_count ++;
6859: }
6860: }
6861: }
6862: if (need_bubble_count) {
6863: alert("$warning");
6864: return;
6865: }
6866: form.submit();
6867: }
6868: </script>
6869: ENDSCRIPT
6870: return $output;
6871: }
6872:
1.497 foxr 6873: =pod
6874:
6875: =item questions_to_line_list
1.157 albertel 6876:
1.497 foxr 6877: Converts a list of questions into a string of comma separated
6878: line numbers in the answer sheet used by the questions. This is
6879: used to fill in the scantron_questions form field.
6880:
6881: Arguments:
6882: questions - Reference to an array of questions.
6883:
6884: =cut
6885:
6886:
6887: sub questions_to_line_list {
6888: my ($questions) = @_;
6889: my @lines;
6890:
1.503 raeburn 6891: foreach my $item (@{$questions}) {
6892: my $question = $item;
6893: my ($first,$count,$last);
6894: if ($item =~ /^(\d+)\.(\d+)$/) {
6895: $question = $1;
6896: my $subquestion = $2;
6897: $first = $first_bubble_line{$question-1} + 1;
6898: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
6899: my $subcount = 1;
6900: while ($subcount<$subquestion) {
6901: $first += $subans[$subcount-1];
6902: $subcount ++;
6903: }
6904: $count = $subans[$subquestion-1];
6905: } else {
6906: $first = $first_bubble_line{$question-1} + 1;
6907: $count = $bubble_lines_per_response{$question-1};
6908: }
1.506 raeburn 6909: $last = $first+$count-1;
1.503 raeburn 6910: push(@lines, ($first..$last));
1.497 foxr 6911: }
6912: return join(',', @lines);
6913: }
6914:
6915: =pod
6916:
6917: =item prompt_for_corrections
6918:
6919: Prompts for a potentially multiline correction to the
6920: user's bubbling (factors out common code from scantron_get_correction
6921: for multi and missing bubble cases).
6922:
6923: Arguments:
6924: $r - Apache request object.
6925: $question - The question number to prompt for.
6926: $scan_config - The scantron file configuration hash.
6927: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 6928: $error - Type of error
1.497 foxr 6929:
6930: Implicit inputs:
6931: %bubble_lines_per_response - Starting line numbers for each question.
6932: Numbered from 0 (but question numbers are from
6933: 1.
6934: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 6935: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
6936: type problems render as separate sub-questions,
1.503 raeburn 6937: in exam mode. This hash contains a
6938: comma-separated list of the lines per
6939: sub-question.
1.510 raeburn 6940: %responsetype_per_response - essayresponse, formularesponse,
6941: stringresponse, imageresponse, reactionresponse,
6942: and organicresponse type problem parts can have
1.503 raeburn 6943: multiple lines per response if the weight
6944: assigned exceeds 10. In this case, only
6945: one bubble per line is permitted, but more
6946: than one line might contain bubbles, e.g.
6947: bubbling of: line 1 - J, line 2 - J,
6948: line 3 - B would assign 22 points.
1.497 foxr 6949:
6950: =cut
6951:
6952: sub prompt_for_corrections {
1.503 raeburn 6953: my ($r, $question, $scan_config, $scan_record, $error) = @_;
6954: my ($current_line,$lines);
6955: my @linenums;
6956: my $questionnum = $question;
6957: if ($question =~ /^(\d+)\.(\d+)$/) {
6958: $question = $1;
6959: $current_line = $first_bubble_line{$question-1} + 1 ;
6960: my $subquestion = $2;
6961: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
6962: my $subcount = 1;
6963: while ($subcount<$subquestion) {
6964: $current_line += $subans[$subcount-1];
6965: $subcount ++;
6966: }
6967: $lines = $subans[$subquestion-1];
6968: } else {
6969: $current_line = $first_bubble_line{$question-1} + 1 ;
6970: $lines = $bubble_lines_per_response{$question-1};
6971: }
1.497 foxr 6972: if ($lines > 1) {
1.503 raeburn 6973: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
6974: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
6975: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 6976: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
6977: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
6978: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
6979: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.503 raeburn 6980: $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 />');
6981: } else {
6982: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
6983: }
1.497 foxr 6984: }
6985: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 6986: my $selected = $$scan_record{"scantron.$current_line.answer"};
6987: &scantron_bubble_selector($r,$scan_config,$current_line,
6988: $questionnum,$error,split('', $selected));
1.524 raeburn 6989: push(@linenums,$current_line);
1.497 foxr 6990: $current_line++;
6991: }
6992: if ($lines > 1) {
6993: $r->print("<hr /><br />");
6994: }
1.503 raeburn 6995: return @linenums;
1.157 albertel 6996: }
1.423 albertel 6997:
6998: =pod
6999:
7000: =item scantron_bubble_selector
7001:
7002: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7003: possibly showing the existing the selected bubbles if known
1.423 albertel 7004:
7005: Arguments:
7006: $r - Apache request object
7007: $scan_config - hash from &get_scantron_config()
1.497 foxr 7008: $line - Number of the line being displayed.
1.503 raeburn 7009: $questionnum - Question number (may include subquestion)
7010: $error - Type of error.
1.497 foxr 7011: @selected - Array of bubbles picked on this line.
1.423 albertel 7012:
7013: =cut
7014:
1.157 albertel 7015: sub scantron_bubble_selector {
1.503 raeburn 7016: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7017: my $max=$$scan_config{'Qlength'};
1.274 albertel 7018:
7019: my $scmode=$$scan_config{'Qon'};
7020: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7021:
1.157 albertel 7022: my @alphabet=('A'..'Z');
1.503 raeburn 7023: $r->print(&Apache::loncommon::start_data_table().
7024: &Apache::loncommon::start_data_table_row());
7025: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7026: for (my $i=0;$i<$max+1;$i++) {
7027: $r->print("\n".'<td align="center">');
7028: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7029: else { $r->print(' '); }
7030: $r->print('</td>');
7031: }
1.503 raeburn 7032: $r->print(&Apache::loncommon::end_data_table_row().
7033: &Apache::loncommon::start_data_table_row());
1.497 foxr 7034: for (my $i=0;$i<$max;$i++) {
7035: $r->print("\n".
7036: '<td><label><input type="radio" name="scantron_correct_Q_'.
7037: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7038: }
1.503 raeburn 7039: my $nobub_checked = ' ';
7040: if ($error eq 'missingbubble') {
7041: $nobub_checked = ' checked = "checked" ';
7042: }
7043: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7044: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7045: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7046: $line.'" value="'.$questionnum.'" /></td>');
7047: $r->print(&Apache::loncommon::end_data_table_row().
7048: &Apache::loncommon::end_data_table());
1.157 albertel 7049: }
7050:
1.423 albertel 7051: =pod
7052:
7053: =item num_matches
7054:
1.424 albertel 7055: Counts the number of characters that are the same between the two arguments.
7056:
7057: Arguments:
7058: $orig - CODE from the scanline
7059: $code - CODE to match against
7060:
7061: Returns:
7062: $count - integer count of the number of same characters between the
7063: two arguments
7064:
1.423 albertel 7065: =cut
7066:
1.194 albertel 7067: sub num_matches {
7068: my ($orig,$code) = @_;
7069: my @code=split(//,$code);
7070: my @orig=split(//,$orig);
7071: my $same=0;
7072: for (my $i=0;$i<scalar(@code);$i++) {
7073: if ($code[$i] eq $orig[$i]) { $same++; }
7074: }
7075: return $same;
7076: }
7077:
1.423 albertel 7078: =pod
7079:
7080: =item scantron_get_closely_matching_CODEs
7081:
1.424 albertel 7082: Cycles through all CODEs and finds the set that has the greatest
7083: number of same characters as the provided CODE
7084:
7085: Arguments:
7086: $allcodes - hash ref returned by &get_codes()
7087: $CODE - CODE from the current scanline
7088:
7089: Returns:
7090: 2 element list
7091: - first elements is number of how closely matching the best fit is
7092: (5 means best set has 5 matching characters)
7093: - second element is an arrary ref containing the set of valid CODEs
7094: that best fit the passed in CODE
7095:
1.423 albertel 7096: =cut
7097:
1.194 albertel 7098: sub scantron_get_closely_matching_CODEs {
7099: my ($allcodes,$CODE)=@_;
7100: my @CODEs;
7101: foreach my $testcode (sort(keys(%{$allcodes}))) {
7102: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7103: }
7104:
7105: return ($#CODEs,$CODEs[-1]);
7106: }
7107:
1.423 albertel 7108: =pod
7109:
7110: =item get_codes
7111:
1.424 albertel 7112: Builds a hash which has keys of all of the valid CODEs from the selected
7113: set of remembered CODEs.
7114:
7115: Arguments:
7116: $old_name - name of the set of remembered CODEs
7117: $cdom - domain of the course
7118: $cnum - internal course name
7119:
7120: Returns:
7121: %allcodes - keys are the valid CODEs, values are all 1
7122:
1.423 albertel 7123: =cut
7124:
1.194 albertel 7125: sub get_codes {
1.280 foxr 7126: my ($old_name, $cdom, $cnum) = @_;
7127: if (!$old_name) {
7128: $old_name=$env{'form.scantron_CODElist'};
7129: }
7130: if (!$cdom) {
7131: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7132: }
7133: if (!$cnum) {
7134: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7135: }
1.278 albertel 7136: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7137: $cdom,$cnum);
7138: my %allcodes;
7139: if ($result{"type\0$old_name"} eq 'number') {
7140: %allcodes=map {($_,1)} split(',',$result{$old_name});
7141: } else {
7142: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7143: }
1.194 albertel 7144: return %allcodes;
7145: }
7146:
1.423 albertel 7147: =pod
7148:
7149: =item scantron_validate_CODE
7150:
1.424 albertel 7151: Validates all scanlines in the selected file to not have any
7152: invalid or underspecified CODEs and that none of the codes are
7153: duplicated if this was requested.
7154:
1.423 albertel 7155: =cut
7156:
1.157 albertel 7157: sub scantron_validate_CODE {
7158: my ($r,$currentphase) = @_;
1.257 albertel 7159: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7160: if ($scantron_config{'CODElocation'} &&
7161: $scantron_config{'CODEstart'} &&
7162: $scantron_config{'CODElength'}) {
1.257 albertel 7163: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7164: &FIXME_blow_up()
7165: }
7166: } else {
7167: return (0,$currentphase+1);
7168: }
7169:
7170: my %usedCODEs;
7171:
1.194 albertel 7172: my %allcodes=&get_codes();
1.186 albertel 7173:
1.447 foxr 7174: &scantron_get_maxbubble(); # parse needs the lines per response array.
7175:
1.186 albertel 7176: my ($scanlines,$scan_data)=&scantron_getfile();
7177: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7178: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7179: if ($line=~/^[\s\cz]*$/) { next; }
7180: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7181: $scan_data);
7182: my $CODE=$$scan_record{'scantron.CODE'};
7183: my $error=0;
1.224 albertel 7184: if (!&Apache::lonnet::validCODE($CODE)) {
7185: &scantron_get_correction($r,$i,$scan_record,
7186: \%scantron_config,
7187: $line,'incorrectCODE',\%allcodes);
7188: return(1,$currentphase);
7189: }
1.221 albertel 7190: if (%allcodes && !exists($allcodes{$CODE})
7191: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7192: &scantron_get_correction($r,$i,$scan_record,
7193: \%scantron_config,
1.194 albertel 7194: $line,'incorrectCODE',\%allcodes);
7195: return(1,$currentphase);
1.186 albertel 7196: }
1.214 albertel 7197: if (exists($usedCODEs{$CODE})
1.257 albertel 7198: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7199: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7200: &scantron_get_correction($r,$i,$scan_record,
7201: \%scantron_config,
1.194 albertel 7202: $line,'duplicateCODE',$usedCODEs{$CODE});
7203: return(1,$currentphase);
1.186 albertel 7204: }
1.524 raeburn 7205: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7206: }
1.157 albertel 7207: return (0,$currentphase+1);
7208: }
7209:
1.423 albertel 7210: =pod
7211:
7212: =item scantron_validate_doublebubble
7213:
1.424 albertel 7214: Validates all scanlines in the selected file to not have any
7215: bubble lines with multiple bubbles marked.
7216:
1.423 albertel 7217: =cut
7218:
1.157 albertel 7219: sub scantron_validate_doublebubble {
7220: my ($r,$currentphase) = @_;
7221: #get student info
7222: my $classlist=&Apache::loncoursedata::get_classlist();
7223: my %idmap=&username_to_idmap($classlist);
7224:
7225: #get scantron line setup
1.257 albertel 7226: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7227: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 7228: &scantron_get_maxbubble(); # parse needs the bubble line array.
7229:
1.157 albertel 7230: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7231: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7232: if ($line=~/^[\s\cz]*$/) { next; }
7233: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7234: $scan_data);
7235: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7236: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7237: 'doublebubble',
7238: $$scan_record{'scantron.doubleerror'});
7239: return (1,$currentphase);
7240: }
7241: return (0,$currentphase+1);
7242: }
7243:
1.423 albertel 7244:
1.503 raeburn 7245: sub scantron_get_maxbubble {
1.257 albertel 7246: if (defined($env{'form.scantron_maxbubble'}) &&
7247: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7248: &restore_bubble_lines();
1.257 albertel 7249: return $env{'form.scantron_maxbubble'};
1.191 albertel 7250: }
1.330 albertel 7251:
1.447 foxr 7252: my (undef, undef, $sequence) =
1.257 albertel 7253: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7254:
1.447 foxr 7255: my $navmap=Apache::lonnavmaps::navmap->new();
1.191 albertel 7256: my $map=$navmap->getResourceByUrl($sequence);
7257: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7258:
7259: &Apache::lonxml::clear_problem_counter();
7260:
1.435 foxr 7261: my $uname = $env{'form.student'};
7262: my $udom = $env{'form.userdom'};
7263: my $cid = $env{'request.course.id'};
7264: my $total_lines = 0;
7265: %bubble_lines_per_response = ();
1.447 foxr 7266: %first_bubble_line = ();
1.503 raeburn 7267: %subdivided_bubble_lines = ();
7268: %responsetype_per_response = ();
1.554 raeburn 7269:
1.447 foxr 7270: my $response_number = 0;
7271: my $bubble_line = 0;
1.191 albertel 7272: foreach my $resource (@resources) {
1.542 raeburn 7273: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7274: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7275: foreach my $part_id (@{$parts}) {
7276: my $lines;
7277:
7278: # TODO - make this a persistent hash not an array.
7279:
7280: # optionresponse, matchresponse and rankresponse type items
7281: # render as separate sub-questions in exam mode.
7282: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7283: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7284: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7285: my ($numbub,$numshown);
7286: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7287: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7288: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7289: }
7290: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7291: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7292: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7293: }
7294: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7295: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7296: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7297: }
7298: }
7299: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7300: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7301: }
7302: my $bubbles_per_line = 10;
7303: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7304: if (($numbub % $bubbles_per_line) != 0) {
7305: $inner_bubble_lines++;
7306: }
7307: for (my $i=0; $i<$numshown; $i++) {
7308: $subdivided_bubble_lines{$response_number} .=
7309: $inner_bubble_lines.',';
7310: }
7311: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7312: $lines = $numshown * $inner_bubble_lines;
7313: } else {
7314: $lines = $analysis->{"$part_id.bubble_lines"};
7315: }
7316:
7317: $first_bubble_line{$response_number} = $bubble_line;
7318: $bubble_lines_per_response{$response_number} = $lines;
7319: $responsetype_per_response{$response_number} =
7320: $analysis->{$part_id.'.type'};
7321: $response_number++;
7322:
7323: $bubble_line += $lines;
7324: $total_lines += $lines;
7325: }
7326: }
7327: }
1.552 raeburn 7328: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7329:
7330: &save_bubble_lines();
7331: $env{'form.scantron_maxbubble'} =
7332: $total_lines;
7333: return $env{'form.scantron_maxbubble'};
7334: }
1.523 raeburn 7335:
1.157 albertel 7336: sub scantron_validate_missingbubbles {
7337: my ($r,$currentphase) = @_;
7338: #get student info
7339: my $classlist=&Apache::loncoursedata::get_classlist();
7340: my %idmap=&username_to_idmap($classlist);
7341:
7342: #get scantron line setup
1.257 albertel 7343: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7344: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 7345: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 7346: if (!$max_bubble) { $max_bubble=2**31; }
7347: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7348: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7349: if ($line=~/^[\s\cz]*$/) { next; }
7350: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7351: $scan_data);
7352: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7353: my @to_correct;
1.470 foxr 7354:
7355: # Probably here's where the error is...
7356:
1.157 albertel 7357: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7358: my $lastbubble;
7359: if ($missing =~ /^(\d+)\.(\d+)$/) {
7360: my $question = $1;
7361: my $subquestion = $2;
7362: if (!defined($first_bubble_line{$question -1})) { next; }
7363: my $first = $first_bubble_line{$question-1};
7364: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7365: my $subcount = 1;
7366: while ($subcount<$subquestion) {
7367: $first += $subans[$subcount-1];
7368: $subcount ++;
7369: }
7370: my $count = $subans[$subquestion-1];
7371: $lastbubble = $first + $count;
7372: } else {
7373: if (!defined($first_bubble_line{$missing - 1})) { next; }
7374: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7375: }
7376: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7377: push(@to_correct,$missing);
7378: }
7379: if (@to_correct) {
7380: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7381: $line,'missingbubble',\@to_correct);
7382: return (1,$currentphase);
7383: }
7384:
7385: }
7386: return (0,$currentphase+1);
7387: }
7388:
1.423 albertel 7389:
1.82 albertel 7390: sub scantron_process_students {
1.75 albertel 7391: my ($r) = @_;
1.513 foxr 7392:
1.257 albertel 7393: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7394: my ($symb)=&get_symb($r);
1.513 foxr 7395: if (!$symb) {
7396: return '';
7397: }
1.324 albertel 7398: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7399:
1.257 albertel 7400: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7401: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7402: my $classlist=&Apache::loncoursedata::get_classlist();
7403: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7404: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 7405: my $map=$navmap->getResourceByUrl($sequence);
7406: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 7407: # $r->print("geto ".scalar(@resources)."<br />");
1.554 raeburn 7408: my ($uname,$udom);
1.82 albertel 7409: my $result= <<SCANTRONFORM;
1.81 albertel 7410: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7411: <input type="hidden" name="command" value="scantron_configphase" />
7412: $default_form_data
7413: SCANTRONFORM
1.82 albertel 7414: $r->print($result);
7415:
7416: my @delayqueue;
1.542 raeburn 7417: my (%completedstudents,%scandata);
1.140 albertel 7418:
1.520 www 7419: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7420: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 7421: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 7422: 'Scantron Progress',$count,
1.195 albertel 7423: 'inline',undef,'scantronupload');
1.140 albertel 7424: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7425: 'Processing first student');
1.542 raeburn 7426: $r->print('<br />');
1.140 albertel 7427: my $start=&Time::HiRes::time();
1.158 albertel 7428: my $i=-1;
1.542 raeburn 7429: my $started;
1.447 foxr 7430:
7431: &scantron_get_maxbubble(); # Need the bubble lines array to parse.
1.513 foxr 7432:
7433: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7434: # the user and return.
7435:
7436: if ($ssi_error) {
7437: $r->print("</form>");
7438: &ssi_print_error($r);
7439: $r->print(&show_grading_menu_form($symb));
1.520 www 7440: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7441: return ''; # Dunno why the other returns return '' rather than just returning.
7442: }
1.447 foxr 7443:
1.542 raeburn 7444: my %lettdig = &letter_to_digits();
7445: my $numletts = scalar(keys(%lettdig));
7446:
1.157 albertel 7447: while ($i<$scanlines->{'count'}) {
7448: ($uname,$udom)=('','');
7449: $i++;
1.200 albertel 7450: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7451: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7452: if ($started) {
7453: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7454: 'last student');
7455: }
7456: $started=1;
1.157 albertel 7457: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7458: $scan_data);
7459: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7460: \%idmap,$i)) {
7461: &scantron_add_delay(\@delayqueue,$line,
7462: 'Unable to find a student that matches',1);
7463: next;
7464: }
7465: if (exists $completedstudents{$uname}) {
7466: &scantron_add_delay(\@delayqueue,$line,
7467: 'Student '.$uname.' has multiple sheets',2);
7468: next;
7469: }
7470: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7471:
1.554 raeburn 7472: my %partids_by_symb;
7473: foreach my $resource (@resources) {
7474: my $ressymb = $resource->symb();
7475: my ($analysis,$parts) =
7476: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom); $partids_by_symb{$ressymb} = $parts;
7477: }
7478:
1.330 albertel 7479: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7480: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7481:
7482: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7483: &scantron_putfile($scanlines,$scan_data);
7484: }
1.161 albertel 7485:
1.542 raeburn 7486: my $scancode;
7487: if ((exists($scan_record->{'scantron.CODE'})) &&
7488: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7489: $scancode = $scan_record->{'scantron.CODE'};
7490: } else {
7491: $scancode = '';
7492: }
7493:
7494: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7495: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7496: $ssi_error = 0; # So end of handler error message does not trigger.
7497: $r->print("</form>");
7498: &ssi_print_error($r);
7499: $r->print(&show_grading_menu_form($symb));
7500: &Apache::lonnet::remove_lock($lock);
7501: return ''; # Why return ''? Beats me.
7502: }
1.513 foxr 7503:
1.140 albertel 7504: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7505: if ($env{'form.verifyrecord'}) {
7506: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7507: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7508: chomp($studentdata);
7509: $studentdata =~ s/\r$//;
7510: my $studentrecord = '';
7511: my $counter = -1;
7512: foreach my $resource (@resources) {
1.554 raeburn 7513: my $ressymb = $resource->symb();
1.542 raeburn 7514: ($counter,my $recording) =
7515: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7516: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7517: \%scantron_config,\%lettdig,$numletts);
7518: $studentrecord .= $recording;
7519: }
7520: if ($studentrecord ne $studentdata) {
1.554 raeburn 7521: &Apache::lonxml::clear_problem_counter();
7522: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7523: \@resources,\%partids_by_symb) eq 'ssi_error') {
7524: $ssi_error = 0; # So end of handler error message does not trigger.
7525: $r->print("</form>");
7526: &ssi_print_error($r);
7527: $r->print(&show_grading_menu_form($symb));
7528: &Apache::lonnet::remove_lock($lock);
7529: delete($completedstudents{$uname});
7530: return '';
7531: }
1.542 raeburn 7532: $counter = -1;
7533: $studentrecord = '';
7534: foreach my $resource (@resources) {
1.554 raeburn 7535: my $ressymb = $resource->symb();
1.542 raeburn 7536: ($counter,my $recording) =
7537: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7538: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7539: \%scantron_config,\%lettdig,$numletts);
7540: $studentrecord .= $recording;
7541: }
7542: if ($studentrecord ne $studentdata) {
7543: $r->print('<p><span class="LC_error">');
7544: if ($scancode eq '') {
7545: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7546: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7547: } else {
7548: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7549: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7550: }
7551: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7552: &Apache::loncommon::start_data_table_header_row()."\n".
7553: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7554: &Apache::loncommon::end_data_table_header_row()."\n".
7555: &Apache::loncommon::start_data_table_row().
7556: '<td>'.&mt('Bubble Sheet').'</td>'.
7557: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7558: &Apache::loncommon::end_data_table_row().
7559: &Apache::loncommon::start_data_table_row().
7560: '<td>Stored submissions</td>'.
7561: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7562: &Apache::loncommon::end_data_table_row().
7563: &Apache::loncommon::end_data_table().'</p>');
7564: } else {
7565: $r->print('<br /><span class="LC_warning">'.
7566: &mt('A second grading pass was needed for user: [_1] with ID: [_2], because a mismatch was seen on the first pass.',$uname.':'.$udom,$scan_record->{'scantron.ID'}).'<br />'.
7567: &mt("As a consequence, this user's submission history records two tries.").
7568: '</span><br />');
7569: }
7570: }
7571: }
1.543 raeburn 7572: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7573: } continue {
1.330 albertel 7574: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7575: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7576: }
1.140 albertel 7577: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7578: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7579: # my $lasttime = &Time::HiRes::time()-$start;
7580: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7581:
1.200 albertel 7582: $r->print("</form>");
1.324 albertel 7583: $r->print(&show_grading_menu_form($symb));
1.157 albertel 7584: return '';
1.75 albertel 7585: }
1.157 albertel 7586:
1.542 raeburn 7587: sub grade_student_bubbles {
1.554 raeburn 7588: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7589: if (ref($resources) eq 'ARRAY') {
7590: my $count = 0;
7591: foreach my $resource (@{$resources}) {
7592: my $ressymb = $resource->symb();
7593: my %form = ('submitted' => 'scantron',
7594: 'grade_target' => 'grade',
7595: 'grade_username' => $uname,
7596: 'grade_domain' => $udom,
7597: 'grade_courseid' => $env{'request.course.id'},
7598: 'grade_symb' => $ressymb,
7599: 'CODE' => $scancode
7600: );
7601: if (ref($parts) eq 'HASH') {
7602: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7603: foreach my $part (@{$parts->{$ressymb}}) {
7604: $form{'scantron_questnum_start.'.$part} =
7605: 1+$env{'form.scantron.first_bubble_line.'.$count};
7606: $count++;
7607: }
7608: }
7609: }
7610: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7611: return 'ssi_error' if ($ssi_error);
7612: last if (&Apache::loncommon::connection_aborted($r));
7613: }
1.542 raeburn 7614: }
7615: return;
7616: }
7617:
1.157 albertel 7618: sub scantron_upload_scantron_data {
7619: my ($r)=@_;
1.257 albertel 7620: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 7621: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7622: 'domainid',
7623: 'coursename');
1.257 albertel 7624: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 7625: 'domainid');
1.324 albertel 7626: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.492 albertel 7627: $r->print('
1.157 albertel 7628: <script type="text/javascript" language="javascript">
7629: function checkUpload(formname) {
7630: if (formname.upfile.value == "") {
1.539 riegler 7631: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.157 albertel 7632: return false;
7633: }
7634: formname.submit();
7635: }
7636: </script>
7637:
1.492 albertel 7638: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7639: '.$default_form_data.'
1.181 albertel 7640: <table>
1.492 albertel 7641: <tr><td>'.$select_link.' </td></tr>
7642: <tr><td>'.&mt('Course ID:').' </td>
7643: <td><input name="courseid" type="text" /> </td></tr>
7644: <tr><td>'.&mt('Course Name:').' </td>
7645: <td><input name="coursename" type="text" /> </td></tr>
7646: <tr><td>'.&mt('Domain:').' </td>
7647: <td>'.$domsel.' </td></tr>
7648: <tr><td>'.&mt('File to upload:').'</td>
7649: <td><input type="file" name="upfile" size="50" /></td></tr>
1.181 albertel 7650: </table>
1.492 albertel 7651: <input name="command" value="scantronupload_save" type="hidden" />
7652: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Scantron Data').'" />
1.157 albertel 7653: </form>
1.492 albertel 7654: ');
1.157 albertel 7655: return '';
7656: }
7657:
1.423 albertel 7658:
1.157 albertel 7659: sub scantron_upload_scantron_data_save {
7660: my($r)=@_;
1.324 albertel 7661: my ($symb)=&get_symb($r,1);
1.182 albertel 7662: my $doanotherupload=
7663: '<br /><form action="/adm/grades" method="post">'."\n".
7664: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7665: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7666: '</form>'."\n";
1.257 albertel 7667: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7668: !&Apache::lonnet::allowed('usc',
1.257 albertel 7669: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.492 albertel 7670: $r->print(&mt("You are not allowed to upload Scantron data to the requested course.")."<br />");
1.182 albertel 7671: if ($symb) {
1.324 albertel 7672: $r->print(&show_grading_menu_form($symb));
1.182 albertel 7673: } else {
7674: $r->print($doanotherupload);
7675: }
1.162 albertel 7676: return '';
7677: }
1.257 albertel 7678: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.492 albertel 7679: $r->print(&mt("Doing upload to [_1]",$coursedata{'description'})." <br />");
1.257 albertel 7680: my $fname=$env{'form.upfile.filename'};
1.157 albertel 7681: #FIXME
7682: #copied from lonnet::userfileupload()
7683: #make that function able to target a specified course
7684: # Replace Windows backslashes by forward slashes
7685: $fname=~s/\\/\//g;
7686: # Get rid of everything but the actual filename
7687: $fname=~s/^.*\/([^\/]+)$/$1/;
7688: # Replace spaces by underscores
7689: $fname=~s/\s+/\_/g;
7690: # Replace all other weird characters by nothing
7691: $fname=~s/[^\w\.\-]//g;
7692: # See if there is anything left
7693: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 7694: my $uploadedfile=$fname;
1.157 albertel 7695: $fname='scantron_orig_'.$fname;
1.257 albertel 7696: if (length($env{'form.upfile'}) < 2) {
1.492 albertel 7697: $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 7698: } else {
1.275 albertel 7699: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 7700: if ($result =~ m|^/uploaded/|) {
1.492 albertel 7701: $r->print(&mt("<span class=\"LC_success\">Success:</span> Successfully uploaded [_1] bytes of data into location [_2]",
7702: (length($env{'form.upfile'})-1),
7703: '<span class="LC_filename">'.$result."</span>"));
1.210 albertel 7704: } else {
1.492 albertel 7705: $r->print(&mt("<span class=\"LC_error\">Error:</span> An error ([_1]) occurred when attempting to upload the file, [_2]",
7706: $result,
7707: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</span>"));
7708:
1.183 albertel 7709: }
7710: }
1.174 albertel 7711: if ($symb) {
1.209 ng 7712: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 7713: } else {
1.182 albertel 7714: $r->print($doanotherupload);
1.174 albertel 7715: }
1.157 albertel 7716: return '';
7717: }
7718:
1.202 albertel 7719: sub valid_file {
7720: my ($requested_file)=@_;
7721: foreach my $filename (sort(&scantron_filenames())) {
7722: if ($requested_file eq $filename) { return 1; }
7723: }
7724: return 0;
7725: }
7726:
7727: sub scantron_download_scantron_data {
7728: my ($r)=@_;
1.324 albertel 7729: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 7730: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7731: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7732: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 7733: if (! &valid_file($file)) {
1.492 albertel 7734: $r->print('
1.202 albertel 7735: <p>
1.492 albertel 7736: '.&mt('The requested file name was invalid.').'
1.202 albertel 7737: </p>
1.492 albertel 7738: ');
1.324 albertel 7739: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7740: return;
7741: }
7742: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
7743: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
7744: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
7745: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
7746: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
7747: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 7748: $r->print('
1.202 albertel 7749: <p>
1.492 albertel 7750: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
7751: '<a href="'.$orig.'">','</a>').'
1.202 albertel 7752: </p>
7753: <p>
1.492 albertel 7754: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
7755: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 7756: </p>
7757: <p>
1.492 albertel 7758: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
7759: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 7760: </p>
1.492 albertel 7761: ');
1.324 albertel 7762: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7763: return '';
7764: }
1.157 albertel 7765:
1.523 raeburn 7766: sub checkscantron_results {
7767: my ($r) = @_;
7768: my ($symb)=&get_symb($r);
7769: if (!$symb) {return '';}
7770: my $grading_menu_button=&show_grading_menu_form($symb);
7771: my $cid = $env{'request.course.id'};
1.542 raeburn 7772: my %lettdig = &letter_to_digits();
1.523 raeburn 7773: my $numletts = scalar(keys(%lettdig));
7774: my $cnum = $env{'course.'.$cid.'.num'};
7775: my $cdom = $env{'course.'.$cid.'.domain'};
7776: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
7777: my %record;
7778: my %scantron_config =
7779: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
7780: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
7781: my $classlist=&Apache::loncoursedata::get_classlist();
7782: my %idmap=&Apache::grades::username_to_idmap($classlist);
7783: my $navmap=Apache::lonnavmaps::navmap->new();
7784: my $map=$navmap->getResourceByUrl($sequence);
7785: my @resources=$navmap->retrieveResources($map,undef,1,0);
1.554 raeburn 7786: my ($uname,$udom);
1.523 raeburn 7787: my (%scandata,%lastname,%bylast);
7788: $r->print('
7789: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
7790:
7791: my @delayqueue;
7792: my %completedstudents;
7793:
7794: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
7795: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron/Submissions Comparison Status',
7796: 'Progress of Scantron Data/Submission Records Comparison',$count,
7797: 'inline',undef,'checkscantron');
1.546 raeburn 7798: my ($username,$domain,$started);
1.523 raeburn 7799:
7800: &Apache::grades::scantron_get_maxbubble(); # Need the bubble lines array to parse.
7801:
7802: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7803: 'Processing first student');
7804: my $start=&Time::HiRes::time();
7805: my $i=-1;
7806:
7807: while ($i<$scanlines->{'count'}) {
7808: ($username,$domain,$uname)=('','','');
7809: $i++;
7810: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
7811: if ($line=~/^[\s\cz]*$/) { next; }
7812: if ($started) {
7813: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7814: 'last student');
7815: }
7816: $started=1;
7817: my $scan_record=
7818: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
7819: $scan_data);
7820: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
7821: \%idmap,$i)) {
7822: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
7823: 'Unable to find a student that matches',1);
7824: next;
7825: }
7826: if (exists $completedstudents{$uname}) {
7827: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
7828: 'Student '.$uname.' has multiple sheets',2);
7829: next;
7830: }
7831: my $pid = $scan_record->{'scantron.ID'};
7832: $lastname{$pid} = $scan_record->{'scantron.LastName'};
7833: push(@{$bylast{$lastname{$pid}}},$pid);
7834: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7835: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7836: chomp($scandata{$pid});
7837: $scandata{$pid} =~ s/\r$//;
7838: ($username,$domain)=split(/:/,$uname);
7839: my $counter = -1;
7840: foreach my $resource (@resources) {
1.554 raeburn 7841: my $ressymb = $resource->symb();
7842: my ($analysis,$parts) =
7843: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
1.542 raeburn 7844: ($counter,my $recording) =
7845: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 7846: $scandata{$pid},$parts,
1.542 raeburn 7847: \%scantron_config,\%lettdig,$numletts);
7848: $record{$pid} .= $recording;
1.523 raeburn 7849: }
7850: }
7851: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
7852: $r->print('<br />');
7853: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
7854: $passed = 0;
7855: $failed = 0;
7856: $numstudents = 0;
7857: foreach my $last (sort(keys(%bylast))) {
7858: if (ref($bylast{$last}) eq 'ARRAY') {
7859: foreach my $pid (sort(@{$bylast{$last}})) {
7860: my $showscandata = $scandata{$pid};
7861: my $showrecord = $record{$pid};
7862: $showscandata =~ s/\s/ /g;
7863: $showrecord =~ s/\s/ /g;
7864: if ($scandata{$pid} eq $record{$pid}) {
7865: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
7866: $okstudents .= '<tr class="'.$css_class.'">'.
7867: '<td>'.&mt('Scantron').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
7868: '</tr>'."\n".
7869: '<tr class="'.$css_class.'">'."\n".
7870: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
7871: $passed ++;
7872: } else {
7873: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
7874: $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".
7875: '</tr>'."\n".
7876: '<tr class="'.$css_class.'">'."\n".
7877: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
7878: '</tr>'."\n";
7879: $failed ++;
7880: }
7881: $numstudents ++;
7882: }
7883: }
7884: }
7885: $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>');
7886: $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>');
7887: if ($passed) {
7888: $r->print(&mt('Students with exact correspondence between scantron data and submissions are as follows:').'<br /><br />');
7889: $r->print(&Apache::loncommon::start_data_table()."\n".
7890: &Apache::loncommon::start_data_table_header_row()."\n".
7891: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
7892: &Apache::loncommon::end_data_table_header_row()."\n".
7893: $okstudents."\n".
7894: &Apache::loncommon::end_data_table().'<br />');
7895: }
7896: if ($failed) {
7897: $r->print(&mt('Students with differences between scantron data and submissions are as follows:').'<br /><br />');
7898: $r->print(&Apache::loncommon::start_data_table()."\n".
7899: &Apache::loncommon::start_data_table_header_row()."\n".
7900: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
7901: &Apache::loncommon::end_data_table_header_row()."\n".
7902: $badstudents."\n".
7903: &Apache::loncommon::end_data_table()).'<br />'.
7904: &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.');
7905: }
7906: $r->print('</form><br />'.$grading_menu_button);
7907: return;
7908: }
7909:
1.542 raeburn 7910: sub verify_scantron_grading {
1.554 raeburn 7911: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 7912: $scantron_config,$lettdig,$numletts) = @_;
7913: my ($record,%expected,%startpos);
7914: return ($counter,$record) if (!ref($resource));
7915: return ($counter,$record) if (!$resource->is_problem());
7916: my $symb = $resource->symb();
1.554 raeburn 7917: return ($counter,$record) if (ref($partids) ne 'ARRAY');
7918: foreach my $part_id (@{$partids}) {
1.542 raeburn 7919: $counter ++;
7920: $expected{$part_id} = 0;
7921: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
7922: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
7923: foreach my $item (@sub_lines) {
7924: $expected{$part_id} += $item;
7925: }
7926: } else {
7927: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
7928: }
7929: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
7930: }
7931: if ($symb) {
7932: my %recorded;
7933: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
7934: if ($returnhash{'version'}) {
7935: my %lasthash=();
7936: my $version;
7937: for ($version=1;$version<=$returnhash{'version'};$version++) {
7938: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
7939: $lasthash{$key}=$returnhash{$version.':'.$key};
7940: }
7941: }
7942: foreach my $key (keys(%lasthash)) {
7943: if ($key =~ /\.scantron$/) {
7944: my $value = &unescape($lasthash{$key});
7945: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
7946: if ($value eq '') {
7947: for (my $i=0; $i<$expected{$part_id}; $i++) {
7948: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
7949: $recorded{$part_id} .= $scantron_config->{'Qoff'};
7950: }
7951: }
7952: } else {
7953: my @tocheck;
7954: my @items = split(//,$value);
7955: if (($scantron_config->{'Qon'} eq 'letter') ||
7956: ($scantron_config->{'Qon'} eq 'number')) {
7957: if (@items < $expected{$part_id}) {
7958: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
7959: my @singles = split(//,$fragment);
7960: foreach my $pos (@singles) {
7961: if ($pos eq ' ') {
7962: push(@tocheck,$pos);
7963: } else {
7964: my $next = shift(@items);
7965: push(@tocheck,$next);
7966: }
7967: }
7968: } else {
7969: @tocheck = @items;
7970: }
7971: foreach my $letter (@tocheck) {
7972: if ($scantron_config->{'Qon'} eq 'letter') {
7973: if ($letter !~ /^[A-J]$/) {
7974: $letter = $scantron_config->{'Qoff'};
7975: }
7976: $recorded{$part_id} .= $letter;
7977: } elsif ($scantron_config->{'Qon'} eq 'number') {
7978: my $digit;
7979: if ($letter !~ /^[A-J]$/) {
7980: $digit = $scantron_config->{'Qoff'};
7981: } else {
7982: $digit = $lettdig->{$letter};
7983: }
7984: $recorded{$part_id} .= $digit;
7985: }
7986: }
7987: } else {
7988: @tocheck = @items;
7989: for (my $i=0; $i<$expected{$part_id}; $i++) {
7990: my $curr_sub = shift(@tocheck);
7991: my $digit;
7992: if ($curr_sub =~ /^[A-J]$/) {
7993: $digit = $lettdig->{$curr_sub}-1;
7994: }
7995: if ($curr_sub eq 'J') {
7996: $digit += scalar($numletts);
7997: }
7998: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
7999: if ($j == $digit) {
8000: $recorded{$part_id} .= $scantron_config->{'Qon'};
8001: } else {
8002: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8003: }
8004: }
8005: }
8006: }
8007: }
8008: }
8009: }
8010: }
1.554 raeburn 8011: foreach my $part_id (@{$partids}) {
1.542 raeburn 8012: if ($recorded{$part_id} eq '') {
8013: for (my $i=0; $i<$expected{$part_id}; $i++) {
8014: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8015: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8016: }
8017: }
8018: }
8019: $record .= $recorded{$part_id};
8020: }
8021: }
8022: return ($counter,$record);
8023: }
8024:
8025: sub letter_to_digits {
8026: my %lettdig = (
8027: A => 1,
8028: B => 2,
8029: C => 3,
8030: D => 4,
8031: E => 5,
8032: F => 6,
8033: G => 7,
8034: H => 8,
8035: I => 9,
8036: J => 0,
8037: );
8038: return %lettdig;
8039: }
8040:
1.423 albertel 8041:
1.75 albertel 8042: #-------- end of section for handling grading scantron forms -------
8043: #
8044: #-------------------------------------------------------------------
8045:
1.72 ng 8046: #-------------------------- Menu interface -------------------------
8047: #
8048: #--- Show a Grading Menu button - Calls the next routine ---
8049: sub show_grading_menu_form {
1.324 albertel 8050: my ($symb)=@_;
1.125 ng 8051: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8052: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8053: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8054: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8055: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8056: '</form>'."\n";
8057: return $result;
8058: }
8059:
1.77 ng 8060: # -- Retrieve choices for grading form
8061: sub savedState {
8062: my %savedState = ();
1.257 albertel 8063: if ($env{'form.saveState'}) {
8064: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8065: my ($key,$value) = split(/=/,$_,2);
8066: $savedState{$key} = $value;
8067: }
8068: }
8069: return \%savedState;
8070: }
1.76 ng 8071:
1.443 banghart 8072: sub grading_menu {
8073: my ($request) = @_;
8074: my ($symb)=&get_symb($request);
8075: if (!$symb) {return '';}
8076: my $probTitle = &Apache::lonnet::gettitle($symb);
8077: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8078:
1.444 banghart 8079: $request->print($table);
1.443 banghart 8080: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8081: 'handgrade'=>$hdgrade,
8082: 'probTitle'=>$probTitle,
8083: 'command'=>'submit_options',
8084: 'saveState'=>"",
8085: 'gradingMenu'=>1,
8086: 'showgrading'=>"yes");
1.538 schulted 8087:
8088: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8089:
1.443 banghart 8090: $fields{'command'} = 'csvform';
1.538 schulted 8091: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8092:
1.443 banghart 8093: $fields{'command'} = 'processclicker';
1.538 schulted 8094: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8095:
1.443 banghart 8096: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8097: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8098:
8099: my @menu = ({ categorytitle=>'Course Grading',
8100: items =>[
8101: { linktext => 'Manual Grading/View Submissions',
8102: url => $url1,
8103: permission => 'F',
8104: icon => 'edit-find-replace.png',
8105: linktitle => 'Start the process of hand grading submissions.'
8106: },
8107: { linktext => 'Upload Scores',
8108: url => $url2,
8109: permission => 'F',
8110: icon => 'uploadscores.png',
8111: linktitle => 'Specify a file containing the class scores for current resource.'
8112: },
8113: { linktext => 'Process Clicker',
8114: url => $url3,
8115: permission => 'F',
8116: icon => 'addClickerInfoFile.png',
8117: linktitle => 'Specify a file containing the clicker information for this resource.'
8118: },
8119: { linktext => 'Grade/Manage/Review Scantron Forms',
8120: url => $url4,
8121: permission => 'F',
8122: icon => 'stat.png',
8123: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
8124: }
8125: ]
8126: });
8127:
8128: #$fields{'command'} = 'verify';
8129: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8130: #
8131: # Create the menu
8132: my $Str;
1.444 banghart 8133: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8134: $Str .= '<form method="post" action="" name="gradingMenu">';
8135: $Str .= '<input type="hidden" name="command" value="" />'.
8136: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8137: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8138: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8139: '<input type="hidden" name="saveState" value="" />'."\n".
8140: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8141: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8142:
1.538 schulted 8143: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8144: #$menudata->{'jscript'}
8145: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt').'" '.
8146: ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
8147: ' /> '.
8148: &Apache::lonnet::recprefix($env{'request.course.id'}).
8149: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />';
8150:
1.444 banghart 8151: $Str .="</form>\n";
1.539 riegler 8152: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8153: $request->print(<<GRADINGMENUJS);
8154: <script type="text/javascript" language="javascript">
8155: function checkChoice(formname,val,cmdx) {
8156: if (val <= 2) {
8157: var cmd = radioSelection(formname.radioChoice);
8158: var cmdsave = cmd;
8159: } else {
8160: cmd = cmdx;
8161: cmdsave = 'submission';
8162: }
8163: formname.command.value = cmd;
8164: if (val < 5) formname.submit();
8165: if (val == 5) {
1.458 banghart 8166: if (!checkReceiptNo(formname,'notOK')) {
8167: return false;
8168: } else {
8169: formname.submit();
8170: }
1.445 banghart 8171: }
8172: }
1.443 banghart 8173:
8174: function checkReceiptNo(formname,nospace) {
8175: var receiptNo = formname.receipt.value;
8176: var checkOpt = false;
8177: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8178: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8179: if (checkOpt) {
1.539 riegler 8180: alert("$receiptalert");
1.443 banghart 8181: formname.receipt.value = "";
8182: formname.receipt.focus();
8183: return false;
8184: }
8185: return true;
8186: }
8187: </script>
8188: GRADINGMENUJS
8189: &commonJSfunctions($request);
8190: return $Str;
8191: }
8192:
8193:
8194: #--- Displays the submissions first page -------
8195: sub submit_options {
1.72 ng 8196: my ($request) = @_;
1.324 albertel 8197: my ($symb)=&get_symb($request);
1.72 ng 8198: if (!$symb) {return '';}
1.76 ng 8199: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8200:
1.539 riegler 8201: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8202: $request->print(<<GRADINGMENUJS);
8203: <script type="text/javascript" language="javascript">
1.116 ng 8204: function checkChoice(formname,val,cmdx) {
8205: if (val <= 2) {
8206: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8207: var cmdsave = cmd;
1.116 ng 8208: } else {
8209: cmd = cmdx;
1.118 ng 8210: cmdsave = 'submission';
1.116 ng 8211: }
8212: formname.command.value = cmd;
1.118 ng 8213: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8214: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8215: if (val < 5) formname.submit();
8216: if (val == 5) {
1.72 ng 8217: if (!checkReceiptNo(formname,'notOK')) { return false;}
8218: formname.submit();
8219: }
1.238 albertel 8220: if (val < 7) formname.submit();
1.72 ng 8221: }
8222:
8223: function checkReceiptNo(formname,nospace) {
8224: var receiptNo = formname.receipt.value;
8225: var checkOpt = false;
8226: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8227: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8228: if (checkOpt) {
1.539 riegler 8229: alert("$receiptalert");
1.72 ng 8230: formname.receipt.value = "";
8231: formname.receipt.focus();
8232: return false;
8233: }
8234: return true;
8235: }
8236: </script>
8237: GRADINGMENUJS
1.118 ng 8238: &commonJSfunctions($request);
1.324 albertel 8239: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8240: my $result;
1.76 ng 8241: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8242: my $savedState = &savedState();
1.118 ng 8243: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8244: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8245: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8246: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8247:
1.533 bisitz 8248: # Preselect sections
8249: my $selsec="";
8250: if (ref($sections)) {
8251: foreach my $section (sort(@$sections)) {
8252: $selsec.='<option value="'.$section.'" '.
8253: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8254: }
8255: }
8256:
1.72 ng 8257: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8258: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8259: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8260: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8261: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8262: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8263: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8264: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8265:
1.472 albertel 8266: $result.='
1.533 bisitz 8267: <h2>
8268: '.&mt('Grade Current Resource').'
8269: </h2>
8270: <div>
8271: '.$table.'
8272: </div>
8273:
1.537 harmsja 8274: <div class="LC_columnSection">
8275:
1.533 bisitz 8276: <fieldset>
8277: <legend>
8278: '.&mt('Sections').'
8279: </legend>
8280: <select name="section" multiple="multiple" size="5">'."\n";
8281: $result.= $selsec;
1.401 albertel 8282: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8283: $result.='
1.533 bisitz 8284: </fieldset>
1.537 harmsja 8285:
1.533 bisitz 8286: <fieldset>
8287: <legend>
8288: '.&mt('Groups').'
8289: </legend>
8290: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8291: </fieldset>
1.537 harmsja 8292:
1.533 bisitz 8293: <fieldset>
8294: <legend>
8295: '.&mt('Access Status').'
8296: </legend>
8297: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8298: </fieldset>
1.537 harmsja 8299:
1.533 bisitz 8300: <fieldset>
8301: <legend>
8302: '.&mt('Submission Status').'
8303: </legend>
8304: <select name="submitonly" size="5">
1.473 albertel 8305: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8306: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8307: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8308: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8309: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8310: </select>
8311: </fieldset>
1.537 harmsja 8312:
1.533 bisitz 8313: </div>
8314:
8315: <br />
8316: <div>
8317: <div>
1.473 albertel 8318: <label>
8319: <input type="radio" name="radioChoice" value="submission" '.
8320: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8321: &mt('Select individual students to grade and view submissions.').'
8322: </label>
8323: </div>
1.533 bisitz 8324: <div>
1.473 albertel 8325: <label>
8326: <input type="radio" name="radioChoice" value="viewgrades" '.
8327: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8328: &mt('Grade all selected students in a grading table.').'
8329: </label>
8330: </div>
1.533 bisitz 8331: <div>
1.539 riegler 8332: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8333: </div>
1.472 albertel 8334: </div>
1.533 bisitz 8335:
8336:
1.473 albertel 8337: <h2>
8338: '.&mt('Grade Complete Folder for One Student').'
8339: </h2>
1.533 bisitz 8340: <div>
8341: <div>
1.473 albertel 8342: <label>
8343: <input type="radio" name="radioChoice" value="pickStudentPage" '.
8344: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
8345: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8346: </label>
8347: </div>
1.533 bisitz 8348: <div>
1.539 riegler 8349: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8350: </div>
1.472 albertel 8351: </div>
8352: </form>';
1.499 albertel 8353: $result .= &show_grading_menu_form($symb);
1.44 ng 8354: return $result;
1.2 albertel 8355: }
8356:
1.285 albertel 8357: sub reset_perm {
8358: undef(%perm);
8359: }
8360:
8361: sub init_perm {
8362: &reset_perm();
1.300 albertel 8363: foreach my $test_perm ('vgr','mgr','opa') {
8364:
8365: my $scope = $env{'request.course.id'};
8366: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8367:
8368: $scope .= '/'.$env{'request.course.sec'};
8369: if ( $perm{$test_perm}=
8370: &Apache::lonnet::allowed($test_perm,$scope)) {
8371: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8372: } else {
8373: delete($perm{$test_perm});
8374: }
1.285 albertel 8375: }
8376: }
8377: }
8378:
1.400 www 8379: sub gather_clicker_ids {
1.408 albertel 8380: my %clicker_ids;
1.400 www 8381:
8382: my $classlist = &Apache::loncoursedata::get_classlist();
8383:
8384: # Set up a couple variables.
1.407 albertel 8385: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8386: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8387: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8388:
1.407 albertel 8389: foreach my $student (keys(%$classlist)) {
1.438 www 8390: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8391: my $username = $classlist->{$student}->[$username_idx];
8392: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8393: my $clickers =
1.408 albertel 8394: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8395: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8396: $id=~s/^[\#0]+//;
1.421 www 8397: $id=~s/[\-\:]//g;
1.407 albertel 8398: if (exists($clicker_ids{$id})) {
1.408 albertel 8399: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8400: } else {
1.408 albertel 8401: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8402: }
8403: }
8404: }
1.407 albertel 8405: return %clicker_ids;
1.400 www 8406: }
8407:
1.402 www 8408: sub gather_adv_clicker_ids {
1.408 albertel 8409: my %clicker_ids;
1.402 www 8410: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8411: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8412: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8413: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8414: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8415: my ($puname,$pudom)=split(/\:/,$person);
8416: my $clickers =
1.408 albertel 8417: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8418: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8419: $id=~s/^[\#0]+//;
1.421 www 8420: $id=~s/[\-\:]//g;
1.408 albertel 8421: if (exists($clicker_ids{$id})) {
8422: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8423: } else {
8424: $clicker_ids{$id}=$puname.':'.$pudom;
8425: }
1.405 www 8426: }
1.402 www 8427: }
8428: }
1.407 albertel 8429: return %clicker_ids;
1.402 www 8430: }
8431:
1.413 www 8432: sub clicker_grading_parameters {
8433: return ('gradingmechanism' => 'scalar',
8434: 'upfiletype' => 'scalar',
8435: 'specificid' => 'scalar',
8436: 'pcorrect' => 'scalar',
8437: 'pincorrect' => 'scalar');
8438: }
8439:
1.400 www 8440: sub process_clicker {
8441: my ($r)=@_;
8442: my ($symb)=&get_symb($r);
8443: if (!$symb) {return '';}
8444: my $result=&checkforfile_js();
8445: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
8446: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
8447: $result.=$table;
8448: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8449: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8450: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8451: '</b></td></tr>'."\n";
1.400 www 8452: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 8453: # Attempt to restore parameters from last session, set defaults if not present
8454: my %Saveable_Parameters=&clicker_grading_parameters();
8455: &Apache::loncommon::restore_course_settings('grades_clicker',
8456: \%Saveable_Parameters);
8457: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8458: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8459: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8460: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8461:
8462: my %checked;
1.521 www 8463: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8464: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
8465: $checked{$gradingmechanism}="checked='checked'";
8466: }
8467: }
8468:
1.400 www 8469: my $upload=&mt("Upload File");
8470: my $type=&mt("Type");
1.402 www 8471: my $attendance=&mt("Award points just for participation");
8472: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8473: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8474: my $given=&mt("Correctness determined from given list of answers").' '.
8475: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8476: my $pcorrect=&mt("Percentage points for correct solution");
8477: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8478: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8479: ('iclicker' => 'i>clicker',
8480: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8481: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 8482: $result.=<<ENDUPFORM;
1.402 www 8483: <script type="text/javascript">
8484: function sanitycheck() {
8485: // Accept only integer percentages
8486: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8487: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8488: // Find out grading choice
8489: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8490: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8491: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8492: }
8493: }
8494: // By default, new choice equals user selection
8495: newgradingchoice=gradingchoice;
8496: // Not good to give more points for false answers than correct ones
8497: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8498: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8499: }
8500: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8501: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8502: document.forms.gradesupload.pcorrect.value=100;
8503: document.forms.gradesupload.pincorrect.value=100;
8504: }
8505: // If the values are different, cannot be attendance only
8506: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8507: (gradingchoice=='attendance')) {
8508: newgradingchoice='personnel';
8509: }
8510: // Change grading choice to new one
8511: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8512: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8513: document.forms.gradesupload.gradingmechanism[i].checked=true;
8514: } else {
8515: document.forms.gradesupload.gradingmechanism[i].checked=false;
8516: }
8517: }
8518: // Remember the old state
8519: document.forms.gradesupload.waschecked.value=newgradingchoice;
8520: }
8521: </script>
1.400 www 8522: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8523: <input type="hidden" name="symb" value="$symb" />
8524: <input type="hidden" name="command" value="processclickerfile" />
8525: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8526: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
8527: <input type="file" name="upfile" size="50" />
8528: <br /><label>$type: $selectform</label>
1.451 albertel 8529: <br /><label><input type="radio" name="gradingmechanism" value="attendance" $checked{'attendance'} onClick="sanitycheck()" />$attendance </label>
8530: <br /><label><input type="radio" name="gradingmechanism" value="personnel" $checked{'personnel'} onClick="sanitycheck()" />$personnel</label>
8531: <br /><label><input type="radio" name="gradingmechanism" value="specific" $checked{'specific'} onClick="sanitycheck()" />$specific </label>
1.414 www 8532: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.521 www 8533: <br /><label><input type="radio" name="gradingmechanism" value="given" $checked{'given'} onClick="sanitycheck()" />$given </label>
8534: <br />
8535: <input type="text" name="givenanswer" size="50" />
1.413 www 8536: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
8537: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onChange="sanitycheck()" /></label>
8538: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onChange="sanitycheck()" /></label>
1.400 www 8539: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
8540: </form>
8541: ENDUPFORM
8542: $result.='</td></tr></table>'."\n".
8543: '</td></tr></table><br /><br />'."\n";
8544: $result.=&show_grading_menu_form($symb);
8545: return $result;
8546: }
8547:
8548: sub process_clicker_file {
8549: my ($r)=@_;
8550: my ($symb)=&get_symb($r);
8551: if (!$symb) {return '';}
1.413 www 8552:
8553: my %Saveable_Parameters=&clicker_grading_parameters();
8554: &Apache::loncommon::store_course_settings('grades_clicker',
8555: \%Saveable_Parameters);
8556:
1.400 www 8557: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 8558: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8559: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
8560: return $result.&show_grading_menu_form($symb);
1.404 www 8561: }
1.522 www 8562: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8563: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
8564: return $result.&show_grading_menu_form($symb);
8565: }
1.522 www 8566: my $foundgiven=0;
1.521 www 8567: if ($env{'form.gradingmechanism'} eq 'given') {
8568: $env{'form.givenanswer'}=~s/^\s*//gs;
8569: $env{'form.givenanswer'}=~s/\s*$//gs;
8570: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8571: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8572: my @answers=split(/\,/,$env{'form.givenanswer'});
8573: $foundgiven=$#answers+1;
1.521 www 8574: }
1.407 albertel 8575: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8576: my %correct_ids;
1.404 www 8577: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8578: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8579: }
8580: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8581: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8582: $correct_id=~tr/a-z/A-Z/;
8583: $correct_id=~s/\s//gs;
8584: $correct_id=~s/^[\#0]+//;
1.421 www 8585: $correct_id=~s/[\-\:]//g;
1.414 www 8586: if ($correct_id) {
8587: $correct_ids{$correct_id}='specified';
8588: }
8589: }
1.400 www 8590: }
1.404 www 8591: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8592: $result.=&mt('Score based on attendance only');
1.521 www 8593: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8594: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8595: } else {
1.408 albertel 8596: my $number=0;
1.411 www 8597: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8598: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8599: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8600: if ($correct_ids{$id} eq 'specified') {
8601: $result.=&mt('specified');
8602: } else {
8603: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
8604: $result.=&Apache::loncommon::plainname($uname,$udom);
8605: }
8606: $number++;
8607: }
1.411 www 8608: $result.="</p>\n";
1.408 albertel 8609: if ($number==0) {
8610: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
8611: return $result.&show_grading_menu_form($symb);
8612: }
1.404 www 8613: }
1.405 www 8614: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 8615: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
8616: '<span class="LC_error">',
8617: '</span>',
8618: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 8619: return $result.&show_grading_menu_form($symb);
8620: }
1.410 www 8621:
8622: # Were able to get all the info needed, now analyze the file
8623:
1.411 www 8624: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 8625: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 8626: my $heading=&mt('Scanning clicker file');
8627: $result.=(<<ENDHEADER);
8628: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8629: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8630: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8631: <form method="post" action="/adm/grades" name="clickeranalysis">
8632: <input type="hidden" name="symb" value="$symb" />
8633: <input type="hidden" name="command" value="assignclickergrades" />
8634: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8635: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 8636: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
8637: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
8638: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 8639: ENDHEADER
1.522 www 8640: if ($env{'form.gradingmechanism'} eq 'given') {
8641: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
8642: }
1.408 albertel 8643: my %responses;
8644: my @questiontitles;
1.405 www 8645: my $errormsg='';
8646: my $number=0;
8647: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 8648: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 8649: }
1.419 www 8650: if ($env{'form.upfiletype'} eq 'interwrite') {
8651: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
8652: }
1.411 www 8653: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
8654: '<input type="hidden" name="number" value="'.$number.'" />'.
8655: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
8656: $env{'form.pcorrect'},$env{'form.pincorrect'}).
8657: '<br />';
1.522 www 8658: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
8659: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
8660: return $result.&show_grading_menu_form($symb);
8661: }
1.414 www 8662: # Remember Question Titles
8663: # FIXME: Possibly need delimiter other than ":"
8664: for (my $i=0;$i<$number;$i++) {
8665: $result.='<input type="hidden" name="question:'.$i.'" value="'.
8666: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
8667: }
1.411 www 8668: my $correct_count=0;
8669: my $student_count=0;
8670: my $unknown_count=0;
1.414 www 8671: # Match answers with usernames
8672: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 8673: foreach my $id (keys(%responses)) {
1.410 www 8674: if ($correct_ids{$id}) {
1.414 www 8675: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 8676: $correct_count++;
1.410 www 8677: } elsif ($clicker_ids{$id}) {
1.437 www 8678: if ($clicker_ids{$id}=~/\,/) {
8679: # More than one user with the same clicker!
8680: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
8681: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8682: "<select name='multi".$id."'>";
8683: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
8684: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
8685: }
8686: $result.='</select>';
8687: $unknown_count++;
8688: } else {
8689: # Good: found one and only one user with the right clicker
8690: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
8691: $student_count++;
8692: }
1.410 www 8693: } else {
1.411 www 8694: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
8695: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8696: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
8697: "\n".&mt("Domain").": ".
8698: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
8699: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
8700: $unknown_count++;
1.410 www 8701: }
1.405 www 8702: }
1.412 www 8703: $result.='<hr />'.
8704: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 8705: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 8706: if ($correct_count==0) {
8707: $errormsg.="Found no correct answers answers for grading!";
8708: } elsif ($correct_count>1) {
1.414 www 8709: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 8710: }
8711: }
1.428 www 8712: if ($number<1) {
8713: $errormsg.="Found no questions.";
8714: }
1.412 www 8715: if ($errormsg) {
8716: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
8717: } else {
8718: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
8719: }
8720: $result.='</form></td></tr></table>'."\n".
1.410 www 8721: '</td></tr></table><br /><br />'."\n";
1.404 www 8722: return $result.&show_grading_menu_form($symb);
1.400 www 8723: }
8724:
1.405 www 8725: sub iclicker_eval {
1.406 www 8726: my ($questiontitles,$responses)=@_;
1.405 www 8727: my $number=0;
8728: my $errormsg='';
8729: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 8730: my %components=&Apache::loncommon::record_sep($line);
8731: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 8732: if ($entries[0] eq 'Question') {
8733: for (my $i=3;$i<$#entries;$i+=6) {
8734: $$questiontitles[$number]=$entries[$i];
8735: $number++;
8736: }
8737: }
8738: if ($entries[0]=~/^\#/) {
8739: my $id=$entries[0];
8740: my @idresponses;
8741: $id=~s/^[\#0]+//;
8742: for (my $i=0;$i<$number;$i++) {
8743: my $idx=3+$i*6;
8744: push(@idresponses,$entries[$idx]);
8745: }
8746: $$responses{$id}=join(',',@idresponses);
8747: }
1.405 www 8748: }
8749: return ($errormsg,$number);
8750: }
8751:
1.419 www 8752: sub interwrite_eval {
8753: my ($questiontitles,$responses)=@_;
8754: my $number=0;
8755: my $errormsg='';
1.420 www 8756: my $skipline=1;
8757: my $questionnumber=0;
8758: my %idresponses=();
1.419 www 8759: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
8760: my %components=&Apache::loncommon::record_sep($line);
8761: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 8762: if ($entries[1] eq 'Time') { $skipline=0; next; }
8763: if ($entries[1] eq 'Response') { $skipline=1; }
8764: next if $skipline;
8765: if ($entries[0]!=$questionnumber) {
8766: $questionnumber=$entries[0];
8767: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
8768: $number++;
1.419 www 8769: }
1.420 www 8770: my $id=$entries[4];
8771: $id=~s/^[\#0]+//;
1.421 www 8772: $id=~s/^v\d*\://i;
8773: $id=~s/[\-\:]//g;
1.420 www 8774: $idresponses{$id}[$number]=$entries[6];
8775: }
1.524 raeburn 8776: foreach my $id (keys(%idresponses)) {
1.420 www 8777: $$responses{$id}=join(',',@{$idresponses{$id}});
8778: $$responses{$id}=~s/^\s*\,//;
1.419 www 8779: }
8780: return ($errormsg,$number);
8781: }
8782:
1.414 www 8783: sub assign_clicker_grades {
8784: my ($r)=@_;
8785: my ($symb)=&get_symb($r);
8786: if (!$symb) {return '';}
1.416 www 8787: # See which part we are saving to
8788: my ($partlist,$handgrade,$responseType) = &response_type($symb);
8789: # FIXME: This should probably look for the first handgradeable part
8790: my $part=$$partlist[0];
8791: # Start screen output
1.414 www 8792: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 8793:
1.414 www 8794: my $heading=&mt('Assigning grades based on clicker file');
8795: $result.=(<<ENDHEADER);
8796: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8797: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8798: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8799: ENDHEADER
8800: # Get correct result
8801: # FIXME: Possibly need delimiter other than ":"
8802: my @correct=();
1.415 www 8803: my $gradingmechanism=$env{'form.gradingmechanism'};
8804: my $number=$env{'form.number'};
8805: if ($gradingmechanism ne 'attendance') {
1.414 www 8806: foreach my $key (keys(%env)) {
8807: if ($key=~/^form\.correct\:/) {
8808: my @input=split(/\,/,$env{$key});
8809: for (my $i=0;$i<=$#input;$i++) {
8810: if (($correct[$i]) && ($input[$i]) &&
8811: ($correct[$i] ne $input[$i])) {
8812: $result.='<br /><span class="LC_warning">'.
8813: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
8814: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
8815: } elsif ($input[$i]) {
8816: $correct[$i]=$input[$i];
8817: }
8818: }
8819: }
8820: }
1.415 www 8821: for (my $i=0;$i<$number;$i++) {
1.414 www 8822: if (!$correct[$i]) {
8823: $result.='<br /><span class="LC_error">'.
8824: &mt('No correct result given for question "[_1]"!',
8825: $env{'form.question:'.$i}).'</span>';
8826: }
8827: }
8828: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
8829: }
8830: # Start grading
1.415 www 8831: my $pcorrect=$env{'form.pcorrect'};
8832: my $pincorrect=$env{'form.pincorrect'};
1.416 www 8833: my $storecount=0;
1.415 www 8834: foreach my $key (keys(%env)) {
1.420 www 8835: my $user='';
1.415 www 8836: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 8837: $user=$1;
8838: }
8839: if ($key=~/^form\.unknown\:(.*)$/) {
8840: my $id=$1;
8841: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
8842: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 8843: } elsif ($env{'form.multi'.$id}) {
8844: $user=$env{'form.multi'.$id};
1.420 www 8845: }
8846: }
8847: if ($user) {
1.415 www 8848: my @answer=split(/\,/,$env{$key});
8849: my $sum=0;
1.522 www 8850: my $realnumber=$number;
1.415 www 8851: for (my $i=0;$i<$number;$i++) {
8852: if ($answer[$i]) {
8853: if ($gradingmechanism eq 'attendance') {
8854: $sum+=$pcorrect;
1.522 www 8855: } elsif ($answer[$i] eq '*') {
8856: $sum+=$pcorrect;
8857: } elsif ($answer[$i] eq '-') {
8858: $realnumber--;
1.415 www 8859: } else {
8860: if ($answer[$i] eq $correct[$i]) {
8861: $sum+=$pcorrect;
8862: } else {
8863: $sum+=$pincorrect;
8864: }
8865: }
8866: }
8867: }
1.522 www 8868: my $ave=$sum/(100*$realnumber);
1.416 www 8869: # Store
8870: my ($username,$domain)=split(/\:/,$user);
8871: my %grades=();
8872: $grades{"resource.$part.solved"}='correct_by_override';
8873: $grades{"resource.$part.awarded"}=$ave;
8874: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
8875: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
8876: $env{'request.course.id'},
8877: $domain,$username);
8878: if ($returncode ne 'ok') {
8879: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
8880: } else {
8881: $storecount++;
8882: }
1.415 www 8883: }
8884: }
8885: # We are done
1.549 hauer 8886: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 8887: '</td></tr></table>'."\n".
1.414 www 8888: '</td></tr></table><br /><br />'."\n";
8889: return $result.&show_grading_menu_form($symb);
8890: }
8891:
1.1 albertel 8892: sub handler {
1.41 ng 8893: my $request=$_[0];
1.434 albertel 8894: &reset_caches();
1.257 albertel 8895: if ($env{'browser.mathml'}) {
1.141 www 8896: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 8897: } else {
1.141 www 8898: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 8899: }
8900: $request->send_http_header;
1.44 ng 8901: return '' if $request->header_only;
1.41 ng 8902: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 8903: my $symb=&get_symb($request,1);
1.160 albertel 8904: my @commands=&Apache::loncommon::get_env_multiple('form.command');
8905: my $command=$commands[0];
1.447 foxr 8906:
1.160 albertel 8907: if ($#commands > 0) {
8908: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
8909: }
1.447 foxr 8910:
1.513 foxr 8911: $ssi_error = 0;
1.535 raeburn 8912: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
8913: $request->print(&Apache::loncommon::start_page('Grading',undef,
8914: {'bread_crumbs' => $brcrum}));
1.324 albertel 8915: if ($symb eq '' && $command eq '') {
1.257 albertel 8916: if ($env{'user.adv'}) {
8917: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
8918: ($env{'form.codethree'})) {
8919: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
8920: $env{'form.codethree'};
1.41 ng 8921: my ($tsymb,$tuname,$tudom,$tcrsid)=
8922: &Apache::lonnet::checkin($token);
8923: if ($tsymb) {
1.137 albertel 8924: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 8925: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 8926: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 8927: ('grade_username' => $tuname,
8928: 'grade_domain' => $tudom,
8929: 'grade_courseid' => $tcrsid,
8930: 'grade_symb' => $tsymb)));
1.41 ng 8931: } else {
1.45 ng 8932: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 8933: }
1.41 ng 8934: } else {
1.45 ng 8935: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 8936: }
1.14 www 8937: } else {
1.41 ng 8938: $request->print(&Apache::lonxml::tokeninputfield());
8939: }
8940: }
8941: } else {
1.285 albertel 8942: &init_perm();
1.104 albertel 8943: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 8944: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 8945: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 8946: &pickStudentPage($request);
1.103 albertel 8947: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 8948: &displayPage($request);
1.104 albertel 8949: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 8950: &updateGradeByPage($request);
1.104 albertel 8951: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 8952: &processGroup($request);
1.104 albertel 8953: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 8954: $request->print(&grading_menu($request));
8955: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
8956: $request->print(&submit_options($request));
1.104 albertel 8957: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 8958: $request->print(&viewgrades($request));
1.104 albertel 8959: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 8960: $request->print(&processHandGrade($request));
1.106 albertel 8961: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 8962: $request->print(&editgrades($request));
1.106 albertel 8963: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 8964: $request->print(&verifyreceipt($request));
1.400 www 8965: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
8966: $request->print(&process_clicker($request));
8967: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
8968: $request->print(&process_clicker_file($request));
1.414 www 8969: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
8970: $request->print(&assign_clicker_grades($request));
1.106 albertel 8971: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 8972: $request->print(&upcsvScores_form($request));
1.106 albertel 8973: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 8974: $request->print(&csvupload($request));
1.106 albertel 8975: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 8976: $request->print(&csvuploadmap($request));
1.246 albertel 8977: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 8978: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 8979: $request->print(&csvuploadoptions($request));
1.41 ng 8980: } else {
1.257 albertel 8981: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
8982: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 8983: } else {
1.257 albertel 8984: $env{'form.upfile_associate'} = 'forward';
1.41 ng 8985: }
8986: $request->print(&csvuploadmap($request));
8987: }
1.246 albertel 8988: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
8989: $request->print(&csvuploadassign($request));
1.106 albertel 8990: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 8991: $request->print(&scantron_selectphase($request));
1.203 albertel 8992: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
8993: $request->print(&scantron_do_warning($request));
1.142 albertel 8994: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
8995: $request->print(&scantron_validate_file($request));
1.106 albertel 8996: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 8997: $request->print(&scantron_process_students($request));
1.157 albertel 8998: } elsif ($command eq 'scantronupload' &&
1.257 albertel 8999: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9000: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9001: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9002: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9003: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9004: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9005: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9006: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9007: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9008: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9009: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9010: $request->print(&checkscantron_results($request));
1.106 albertel 9011: } elsif ($command) {
1.157 albertel 9012: $request->print("Access Denied ($command)");
1.26 albertel 9013: }
1.2 albertel 9014: }
1.513 foxr 9015: if ($ssi_error) {
9016: &ssi_print_error($request);
9017: }
1.353 albertel 9018: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9019: &reset_caches();
1.44 ng 9020: return '';
9021: }
9022:
1.1 albertel 9023: 1;
9024:
1.13 albertel 9025: __END__;
1.531 jms 9026:
9027:
9028: =head1 NAME
9029:
9030: Apache::grades
9031:
9032: =head1 SYNOPSIS
9033:
9034: Handles the viewing of grades.
9035:
9036: This is part of the LearningOnline Network with CAPA project
9037: described at http://www.lon-capa.org.
9038:
9039: =head1 OVERVIEW
9040:
9041: Do an ssi with retries:
9042: While I'd love to factor out this with the vesrion in lonprintout,
9043: 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
9044: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9045:
9046: At least the logic that drives this has been pulled out into loncommon.
9047:
9048:
9049:
9050: ssi_with_retries - Does the server side include of a resource.
9051: if the ssi call returns an error we'll retry it up to
9052: the number of times requested by the caller.
9053: If we still have a proble, no text is appended to the
9054: output and we set some global variables.
9055: to indicate to the caller an SSI error occurred.
9056: All of this is supposed to deal with the issues described
9057: in LonCAPA BZ 5631 see:
9058: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9059: by informing the user that this happened.
9060:
9061: Parameters:
9062: resource - The resource to include. This is passed directly, without
9063: interpretation to lonnet::ssi.
9064: form - The form hash parameters that guide the interpretation of the resource
9065:
9066: retries - Number of retries allowed before giving up completely.
9067: Returns:
9068: On success, returns the rendered resource identified by the resource parameter.
9069: Side Effects:
9070: The following global variables can be set:
9071: ssi_error - If an unrecoverable error occurred this becomes true.
9072: It is up to the caller to initialize this to false
9073: if desired.
9074: ssi_error_resource - If an unrecoverable error occurred, this is the value
9075: of the resource that could not be rendered by the ssi
9076: call.
9077: ssi_error_message - The error string fetched from the ssi response
9078: in the event of an error.
9079:
9080:
9081: =head1 HANDLER SUBROUTINE
9082:
9083: ssi_with_retries()
9084:
9085: =head1 SUBROUTINES
9086:
9087: =over
9088:
9089: =item scantron_get_correction() :
9090:
9091: Builds the interface screen to interact with the operator to fix a
9092: specific error condition in a specific scanline
9093:
9094: Arguments:
9095: $r - Apache request object
9096: $i - number of the current scanline
9097: $scan_record - hash ref as returned from &scantron_parse_scanline()
9098: $scan_config - hash ref as returned from &get_scantron_config()
9099: $line - full contents of the current scanline
9100: $error - error condition, valid values are
9101: 'incorrectCODE', 'duplicateCODE',
9102: 'doublebubble', 'missingbubble',
9103: 'duplicateID', 'incorrectID'
9104: $arg - extra information needed
9105: For errors:
9106: - duplicateID - paper number that this studentID was seen before on
9107: - duplicateCODE - array ref of the paper numbers this CODE was
9108: seen on before
9109: - incorrectCODE - current incorrect CODE
9110: - doublebubble - array ref of the bubble lines that have double
9111: bubble errors
9112: - missingbubble - array ref of the bubble lines that have missing
9113: bubble errors
9114:
9115: =item scantron_get_maxbubble() :
9116:
9117: Returns the maximum number of bubble lines that are expected to
9118: occur. Does this by walking the selected sequence rendering the
9119: resource and then checking &Apache::lonxml::get_problem_counter()
9120: for what the current value of the problem counter is.
9121:
9122: Caches the results to $env{'form.scantron_maxbubble'},
9123: $env{'form.scantron.bubble_lines.n'},
9124: $env{'form.scantron.first_bubble_line.n'} and
9125: $env{"form.scantron.sub_bubblelines.n"}
9126: which are the total number of bubble, lines, the number of bubble
9127: lines for response n and number of the first bubble line for response n,
9128: and a comma separated list of numbers of bubble lines for sub-questions
9129: (for optionresponse, matchresponse, and rankresponse items), for response n.
9130:
9131:
9132: =item scantron_validate_missingbubbles() :
9133:
9134: Validates all scanlines in the selected file to not have any
9135: answers that don't have bubbles that have not been verified
9136: to be bubble free.
9137:
9138: =item scantron_process_students() :
9139:
9140: Routine that does the actual grading of the bubble sheet information.
9141:
9142: The parsed scanline hash is added to %env
9143:
9144: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9145: foreach resource , with the form data of
9146:
9147: 'submitted' =>'scantron'
9148: 'grade_target' =>'grade',
9149: 'grade_username'=> username of student
9150: 'grade_domain' => domain of student
9151: 'grade_courseid'=> of course
9152: 'grade_symb' => symb of resource to grade
9153:
9154: This triggers a grading pass. The problem grading code takes care
9155: of converting the bubbled letter information (now in %env) into a
9156: valid submission.
9157:
9158: =item scantron_upload_scantron_data() :
9159:
9160: Creates the screen for adding a new bubble sheet data file to a course.
9161:
9162: =item scantron_upload_scantron_data_save() :
9163:
9164: Adds a provided bubble information data file to the course if user
9165: has the correct privileges to do so.
9166:
9167: =item valid_file() :
9168:
9169: Validates that the requested bubble data file exists in the course.
9170:
9171: =item scantron_download_scantron_data() :
9172:
9173: Shows a list of the three internal files (original, corrected,
9174: skipped) for a specific bubble sheet data file that exists in the
9175: course.
9176:
9177: =item scantron_validate_ID() :
9178:
9179: Validates all scanlines in the selected file to not have any
1.556 ! weissno 9180: invalid or underspecified student/employee IDs
1.531 jms 9181:
9182: =back
9183:
9184: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>