Annotation of loncom/homework/grades.pm, revision 1.425
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.425 ! albertel 4: # $Id: grades.pm,v 1.424 2007/07/25 00:00:23 albertel 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:
29: package Apache::grades;
30: use strict;
31: use Apache::style;
32: use Apache::lonxml;
33: use Apache::lonnet;
1.3 albertel 34: use Apache::loncommon;
1.112 ng 35: use Apache::lonhtmlcommon;
1.68 ng 36: use Apache::lonnavmaps;
1.1 albertel 37: use Apache::lonhomework;
1.55 matthew 38: use Apache::loncoursedata;
1.362 albertel 39: use Apache::lonmsg();
1.1 albertel 40: use Apache::Constants qw(:common);
1.167 sakharuk 41: use Apache::lonlocal;
1.386 raeburn 42: use Apache::lonenc;
1.170 albertel 43: use String::Similarity;
1.359 www 44: use LONCAPA;
45:
1.315 bowersj2 46: use POSIX qw(floor);
1.87 www 47:
48: my %oldessays=();
1.103 albertel 49: my %perm=();
1.1 albertel 50:
1.68 ng 51: # ----- These first few routines are general use routines.----
1.44 ng 52: #
1.146 albertel 53: # --- Retrieve the parts from the metadata file.---
1.44 ng 54: sub getpartlist {
1.324 albertel 55: my ($symb) = @_;
56: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.146 albertel 57: my $partorder = &Apache::lonnet::metadata($url, 'partorder');
58: my @parts;
59: if ($partorder) {
60: for my $part (split (/,/,$partorder)) {
61: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
62: push(@parts, $part);
63: }
64: }
65: } else {
66: my $metadata = &Apache::lonnet::metadata($url, 'packages');
67: foreach (split(/\,/,$metadata)) {
68: if ($_ =~ /^part_(.*)$/) {
69: if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
70: push(@parts, $1);
71: }
72: }
1.41 ng 73: }
1.16 albertel 74: }
1.146 albertel 75: my @stores;
76: foreach my $part (@parts) {
77: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
78: foreach my $key (@metakeys) {
79: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
80: }
81: }
82: return @stores;
1.2 albertel 83: }
84:
1.44 ng 85: # --- Get the symbolic name of a problem and the url
1.324 albertel 86: sub get_symb {
1.173 albertel 87: my ($request,$silent) = @_;
1.257 albertel 88: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
89: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 90: if ($symb eq '') {
91: if (!$silent) {
92: $request->print("Unable to handle ambiguous references:$url:.");
93: return ();
94: }
95: }
1.418 albertel 96: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 97: return ($symb);
1.32 ng 98: }
99:
1.129 ng 100: #--- Format fullname, username:domain if different for display
101: #--- Use anywhere where the student names are listed
102: sub nameUserString {
103: my ($type,$fullname,$uname,$udom) = @_;
104: if ($type eq 'header') {
1.398 albertel 105: return '<b> Fullname </b><span class="LC_internal_info">(Username)</span>';
1.129 ng 106: } else {
1.398 albertel 107: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
108: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 109: }
110: }
111:
1.44 ng 112: #--- Get the partlist and the response type for a given problem. ---
113: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 114: sub response_type {
1.324 albertel 115: my ($symb) = shift;
1.377 albertel 116:
117: my $navmap = Apache::lonnavmaps::navmap->new();
118: my $res = $navmap->getBySymb($symb);
119: my $partlist = $res->parts();
1.392 albertel 120: my %vPart =
121: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 122: my (%response_types,%handgrade);
123: foreach my $part (@{ $partlist }) {
1.392 albertel 124: next if (%vPart && !exists($vPart{$part}));
125:
1.377 albertel 126: my @types = $res->responseType($part);
127: my @ids = $res->responseIds($part);
128: for (my $i=0; $i < scalar(@ids); $i++) {
129: $response_types{$part}{$ids[$i]} = $types[$i];
130: $handgrade{$part.'_'.$ids[$i]} =
131: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
132: '.handgrade',$symb);
1.41 ng 133: }
134: }
1.377 albertel 135: return ($partlist,\%handgrade,\%response_types);
1.39 ng 136: }
137:
1.375 albertel 138: sub flatten_responseType {
139: my ($responseType) = @_;
140: my @part_response_id =
141: map {
142: my $part = $_;
143: map {
144: [$part,$_]
145: } sort(keys(%{ $responseType->{$part} }));
146: } sort(keys(%$responseType));
147: return @part_response_id;
148: }
149:
1.207 albertel 150: sub get_display_part {
1.324 albertel 151: my ($partID,$symb)=@_;
1.207 albertel 152: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
153: if (defined($display) and $display ne '') {
1.398 albertel 154: $display.= " (<span class=\"LC_internal_info\">id $partID</span>)";
1.207 albertel 155: } else {
156: $display=$partID;
157: }
158: return $display;
159: }
1.269 raeburn 160:
1.118 ng 161: #--- Show resource title
162: #--- and parts and response type
163: sub showResourceInfo {
1.324 albertel 164: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 165: my $col=3;
166: if ($checkboxes) { $col=4; }
1.398 albertel 167: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
168: $result .='<table border="0">';
1.324 albertel 169: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.126 ng 170: my %resptype = ();
1.122 ng 171: my $hdgrade='no';
1.154 albertel 172: my %partsseen;
1.375 albertel 173: foreach my $partID (sort keys(%$responseType)) {
174: foreach my $resID (sort keys(%{ $responseType->{$partID} })) {
175: my $handgrade=$$handgrade{$partID.'_'.$resID};
176: my $responsetype = $responseType->{$partID}->{$resID};
177: $hdgrade = $handgrade if ($handgrade eq 'yes');
178: $result.='<tr>';
179: if ($checkboxes) {
180: if (exists($partsseen{$partID})) {
181: $result.="<td> </td>";
182: } else {
1.401 albertel 183: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
1.375 albertel 184: }
185: $partsseen{$partID}=1;
1.154 albertel 186: }
1.375 albertel 187: my $display_part=&get_display_part($partID,$symb);
1.398 albertel 188: $result.='<td><b>Part: </b>'.$display_part.' <span class="LC_internal_info">'.
189: $resID.'</span></td>'.
1.375 albertel 190: '<td><b>Type: </b>'.$responsetype.'</td></tr>';
191: # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
1.154 albertel 192: }
1.118 ng 193: }
194: $result.='</table>'."\n";
1.147 albertel 195: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 196: }
197:
1.148 albertel 198:
199: sub get_order {
200: my ($partid,$respid,$symb,$uname,$udom)=@_;
201: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
202: $url=&Apache::lonnet::clutter($url);
203: my $subresult=&Apache::lonnet::ssi($url,
204: ('grade_target' => 'analyze'),
205: ('grade_domain' => $udom),
206: ('grade_symb' => $symb),
207: ('grade_courseid' =>
1.257 albertel 208: $env{'request.course.id'}),
1.148 albertel 209: ('grade_username' => $uname));
1.149 albertel 210: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148 albertel 211: my %analyze=&Apache::lonnet::str2hash($subresult);
212: return ($analyze{"$partid.$respid.shown"});
213: }
1.118 ng 214: #--- Clean response type for display
1.335 albertel 215: #--- Currently filters option/rank/radiobutton/match/essay/Task
216: # response types only.
1.118 ng 217: sub cleanRecord {
1.336 albertel 218: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
219: $uname,$udom) = @_;
1.398 albertel 220: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 221: if ($response =~ /^(option|rank)$/) {
222: my %answer=&Apache::lonnet::str2hash($answer);
223: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
224: my ($toprow,$bottomrow);
225: foreach my $foil (@$order) {
226: if ($grading{$foil} == 1) {
227: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
228: } else {
229: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
230: }
1.398 albertel 231: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 232: }
233: return '<blockquote><table border="1">'.
234: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 235: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 236: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
237: } elsif ($response eq 'match') {
238: my %answer=&Apache::lonnet::str2hash($answer);
239: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
240: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
241: my ($toprow,$middlerow,$bottomrow);
242: foreach my $foil (@$order) {
243: my $item=shift(@items);
244: if ($grading{$foil} == 1) {
245: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 246: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 247: } else {
248: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 249: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 250: }
1.398 albertel 251: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 252: }
1.126 ng 253: return '<blockquote><table border="1">'.
1.148 albertel 254: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 255: '<tr valign="top"><td>'.$grayFont.'Item ID</span></td>'.
1.148 albertel 256: $middlerow.'</tr>'.
1.398 albertel 257: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 258: $bottomrow.'</tr>'.'</table></blockquote>';
259: } elsif ($response eq 'radiobutton') {
260: my %answer=&Apache::lonnet::str2hash($answer);
261: my ($toprow,$bottomrow);
262: my $correct=($order->[0])+1;
263: for (my $i=1;$i<=$#$order;$i++) {
264: my $foil=$order->[$i];
265: if (exists($answer{$foil})) {
266: if ($i == $correct) {
267: $toprow.='<td><b>true</b></td>';
268: } else {
269: $toprow.='<td><i>true</i></td>';
270: }
271: } else {
272: $toprow.='<td>false</td>';
273: }
1.398 albertel 274: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 275: }
276: return '<blockquote><table border="1">'.
277: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 278: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 279: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
280: } elsif ($response eq 'essay') {
1.257 albertel 281: if (! exists ($env{'form.'.$symb})) {
1.122 ng 282: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 283: $env{'course.'.$env{'request.course.id'}.'.domain'},
284: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 285:
1.257 albertel 286: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
287: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
288: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
289: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
290: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
291: $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 292: }
1.166 albertel 293: $answer =~ s-\n-<br />-g;
294: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 295: } elsif ( $response eq 'organic') {
296: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
297: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
298: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
299: return $result;
1.335 albertel 300: } elsif ( $response eq 'Task') {
301: if ( $answer eq 'SUBMITTED') {
302: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 303: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 304: return $result;
305: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
306: my @matches = grep(/^\Q$version\E.*?\.instance$/,
307: keys(%{$record}));
308: return join('<br />',($version,@matches));
309:
310:
311: } else {
312: my $result =
313: '<p>'
314: .&mt('Overall result: [_1]',
315: $record->{$version."resource.$respid.$partid.status"})
316: .'</p>';
317:
318: $result .= '<ul>';
319: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
320: keys(%{$record}));
321: foreach my $grade (sort(@grade)) {
322: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
323: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
324: $dim, $record->{$grade}).
325: '</li>';
326: }
327: $result.='</ul>';
328: return $result;
329: }
330:
1.122 ng 331: }
1.118 ng 332: return $answer;
333: }
334:
335: #-- A couple of common js functions
336: sub commonJSfunctions {
337: my $request = shift;
338: $request->print(<<COMMONJSFUNCTIONS);
339: <script type="text/javascript" language="javascript">
340: function radioSelection(radioButton) {
341: var selection=null;
342: if (radioButton.length > 1) {
343: for (var i=0; i<radioButton.length; i++) {
344: if (radioButton[i].checked) {
345: return radioButton[i].value;
346: }
347: }
348: } else {
349: if (radioButton.checked) return radioButton.value;
350: }
351: return selection;
352: }
353:
354: function pullDownSelection(selectOne) {
355: var selection="";
356: if (selectOne.length > 1) {
357: for (var i=0; i<selectOne.length; i++) {
358: if (selectOne[i].selected) {
359: return selectOne[i].value;
360: }
361: }
362: } else {
1.138 albertel 363: // only one value it must be the selected one
364: return selectOne.value;
1.118 ng 365: }
366: }
367: </script>
368: COMMONJSFUNCTIONS
369: }
370:
1.44 ng 371: #--- Dumps the class list with usernames,list of sections,
372: #--- section, ids and fullnames for each user.
373: sub getclasslist {
1.76 ng 374: my ($getsec,$filterlist) = @_;
1.291 albertel 375: my @getsec;
376: if (!ref($getsec)) {
377: if ($getsec ne '' && $getsec ne 'all') {
378: @getsec=($getsec);
379: }
380: } else {
381: @getsec=@{$getsec};
382: }
383: if (grep(/^all$/,@getsec)) { undef(@getsec); }
384:
1.56 matthew 385: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 386: # Bail out if we were unable to get the classlist
1.56 matthew 387: return if (! defined($classlist));
388: #
389: my %sections;
390: my %fullnames;
1.205 matthew 391: foreach my $student (keys(%$classlist)) {
392: my $end =
393: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
394: my $start =
395: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
396: my $id =
397: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
398: my $section =
399: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
400: my $fullname =
401: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
402: my $status =
403: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.76 ng 404: # filter students according to status selected
1.257 albertel 405: if ($filterlist && $env{'form.Status'} ne 'Any') {
406: if ($env{'form.Status'} ne $status) {
1.205 matthew 407: delete ($classlist->{$student});
1.76 ng 408: next;
409: }
410: }
1.205 matthew 411: $section = ($section ne '' ? $section : 'none');
1.106 albertel 412: if (&canview($section)) {
1.291 albertel 413: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 414: $sections{$section}++;
1.205 matthew 415: $fullnames{$student}=$fullname;
1.103 albertel 416: } else {
1.205 matthew 417: delete($classlist->{$student});
1.103 albertel 418: }
419: } else {
1.205 matthew 420: delete($classlist->{$student});
1.103 albertel 421: }
1.44 ng 422: }
423: my %seen = ();
1.56 matthew 424: my @sections = sort(keys(%sections));
425: return ($classlist,\@sections,\%fullnames);
1.44 ng 426: }
427:
1.103 albertel 428: sub canmodify {
429: my ($sec)=@_;
430: if ($perm{'mgr'}) {
431: if (!defined($perm{'mgr_section'})) {
432: # can modify whole class
433: return 1;
434: } else {
435: if ($sec eq $perm{'mgr_section'}) {
436: #can modify the requested section
437: return 1;
438: } else {
439: # can't modify the request section
440: return 0;
441: }
442: }
443: }
444: #can't modify
445: return 0;
446: }
447:
448: sub canview {
449: my ($sec)=@_;
450: if ($perm{'vgr'}) {
451: if (!defined($perm{'vgr_section'})) {
452: # can modify whole class
453: return 1;
454: } else {
455: if ($sec eq $perm{'vgr_section'}) {
456: #can modify the requested section
457: return 1;
458: } else {
459: # can't modify the request section
460: return 0;
461: }
462: }
463: }
464: #can't modify
465: return 0;
466: }
467:
1.44 ng 468: #--- Retrieve the grade status of a student for all the parts
469: sub student_gradeStatus {
1.324 albertel 470: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 471: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 472: my %partstatus = ();
473: foreach (@$partlist) {
1.128 ng 474: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 475: $status = 'nothing' if ($status eq '');
476: $partstatus{$_} = $status;
477: my $subkey = "resource.$_.submitted_by";
478: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
479: }
480: return %partstatus;
481: }
482:
1.45 ng 483: # hidden form and javascript that calls the form
484: # Use by verifyscript and viewgrades
485: # Shows a student's view of problem and submission
486: sub jscriptNform {
1.324 albertel 487: my ($symb) = @_;
1.45 ng 488: my $jscript='<script type="text/javascript" language="javascript">'."\n".
489: ' function viewOneStudent(user,domain) {'."\n".
490: ' document.onestudent.student.value = user;'."\n".
491: ' document.onestudent.userdom.value = domain;'."\n".
492: ' document.onestudent.submit();'."\n".
493: ' }'."\n".
494: '</script>'."\n";
495: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 496: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 497: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
498: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
499: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.45 ng 500: '<input type="hidden" name="command" value="submission" />'."\n".
501: '<input type="hidden" name="student" value="" />'."\n".
502: '<input type="hidden" name="userdom" value="" />'."\n".
503: '</form>'."\n";
504: return $jscript;
505: }
1.39 ng 506:
1.315 bowersj2 507: # Given the score (as a number [0-1] and the weight) what is the final
508: # point value? This function will round to the nearest tenth, third,
509: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 510: sub compute_points {
1.315 bowersj2 511: my ($score, $weight) = @_;
512:
513: my $tolerance = .00001;
514: my $points = $score * $weight;
515:
516: # Check for nearness to 1/x.
517: my $check_for_nearness = sub {
518: my ($factor) = @_;
519: my $num = ($points * $factor) + $tolerance;
520: my $floored_num = floor($num);
1.316 albertel 521: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 522: return $floored_num / $factor;
523: }
524: return $points;
525: };
526:
527: $points = $check_for_nearness->(10);
528: $points = $check_for_nearness->(3);
529: $points = $check_for_nearness->(4);
530:
531: return $points;
532: }
533:
1.44 ng 534: #------------------ End of general use routines --------------------
1.87 www 535:
536: #
537: # Find most similar essay
538: #
539:
540: sub most_similar {
541: my ($uname,$udom,$uessay)=@_;
542:
543: # ignore spaces and punctuation
544:
545: $uessay=~s/\W+/ /gs;
546:
1.282 www 547: # ignore empty submissions (occuring when only files are sent)
548:
549: unless ($uessay=~/\w+/) { return ''; }
550:
1.87 www 551: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 552: my $limit=0.6;
1.87 www 553: my $sname='';
554: my $sdom='';
555: my $scrsid='';
556: my $sessay='';
557: # go through all essays ...
558: foreach my $tkey (keys %oldessays) {
559: my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
560: # ... except the same student
1.88 www 561: if (($tname ne $uname) || ($tdom ne $udom)) {
1.87 www 562: my $tessay=$oldessays{$tkey};
563: $tessay=~s/\W+/ /gs;
564: # String similarity gives up if not even limit
1.88 www 565: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 566: # Found one
567: if ($tsimilar>$limit) {
568: $limit=$tsimilar;
569: $sname=$tname;
1.88 www 570: $sdom=$tdom;
1.87 www 571: $scrsid=$tcrsid;
572: $sessay=$oldessays{$tkey};
573: }
574: }
575: }
1.88 www 576: if ($limit>0.6) {
1.87 www 577: return ($sname,$sdom,$scrsid,$sessay,$limit);
578: } else {
579: return ('','','','',0);
580: }
581: }
582:
1.44 ng 583: #-------------------------------------------------------------------
584:
585: #------------------------------------ Receipt Verification Routines
1.45 ng 586: #
1.44 ng 587: #--- Check whether a receipt number is valid.---
588: sub verifyreceipt {
589: my $request = shift;
590:
1.257 albertel 591: my $courseid = $env{'request.course.id'};
1.184 www 592: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 593: $env{'form.receipt'};
1.44 ng 594: $receipt =~ s/[^\-\d]//g;
1.378 albertel 595: my ($symb) = &get_symb($request);
1.44 ng 596:
1.398 albertel 597: my $title.='<h3><span class="LC_info">Verifying Submission Receipt '.
598: $receipt.'</h3></span>'."\n".
599: '<h4><b>Resource: </b>'.$env{'form.probTitle'}.'</h4><br /><br />'."\n";
1.44 ng 600:
601: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 602: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 603:
604: my $receiptparts=0;
1.390 albertel 605: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
606: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 607: my $parts=['0'];
1.324 albertel 608: if ($receiptparts) { ($parts)=&response_type($symb); }
1.294 albertel 609: foreach (sort
610: {
611: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
612: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
613: }
614: return $a cmp $b;
615: } (keys(%$fullname))) {
1.44 ng 616: my ($uname,$udom)=split(/\:/);
1.177 albertel 617: foreach my $part (@$parts) {
618: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
619: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
620: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 621: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 622: '<td> '.$uname.' </td>'.
623: '<td> '.$udom.' </td>';
624: if ($receiptparts) {
625: $contents.='<td> '.$part.' </td>';
626: }
627: $contents.='</tr>'."\n";
628:
629: $matches++;
630: }
1.44 ng 631: }
632: }
633: if ($matches == 0) {
634: $string = $title.'No match found for the above receipt.';
635: } else {
1.324 albertel 636: $string = &jscriptNform($symb).$title.
1.44 ng 637: 'The above receipt matches the following student'.
638: ($matches <= 1 ? '.' : 's.')."\n".
639: '<table border="0"><tr><td bgcolor="#777777">'."\n".
640: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
641: '<td><b> Fullname </b></td>'."\n".
642: '<td><b> Username </b></td>'."\n".
1.177 albertel 643: '<td><b> Domain </b></td>';
644: if ($receiptparts) {
645: $string.='<td> Problem Part </td>';
646: }
647: $string.='</tr>'."\n".$contents.
1.44 ng 648: '</table></td></tr></table>'."\n";
649: }
1.324 albertel 650: return $string.&show_grading_menu_form($symb);
1.44 ng 651: }
652:
653: #--- This is called by a number of programs.
654: #--- Called from the Grading Menu - View/Grade an individual student
655: #--- Also called directly when one clicks on the subm button
656: # on the problem page.
1.30 ng 657: sub listStudents {
1.41 ng 658: my ($request) = shift;
1.49 albertel 659:
1.324 albertel 660: my ($symb) = &get_symb($request);
1.257 albertel 661: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
662: my $cnum = $env{"course.$env{'request.course.id'}.num"};
663: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
664: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
665:
666: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
667: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
668: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 669:
1.398 albertel 670: my $result='<h3><span class="LC_info"> '.$viewgrade.
671: ' Submissions for a Student or a Group of Students</span></h3>';
1.118 ng 672:
1.324 albertel 673: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 674:
1.45 ng 675: $request->print(<<LISTJAVASCRIPT);
676: <script type="text/javascript" language="javascript">
1.110 ng 677: function checkSelect(checkBox) {
678: var ctr=0;
679: var sense="";
680: if (checkBox.length > 1) {
681: for (var i=0; i<checkBox.length; i++) {
682: if (checkBox[i].checked) {
683: ctr++;
684: }
685: }
686: sense = "a student or group of students";
687: } else {
688: if (checkBox.checked) {
689: ctr = 1;
690: }
691: sense = "the student";
692: }
693: if (ctr == 0) {
1.126 ng 694: alert("Please select "+sense+" before clicking on the Next button.");
1.110 ng 695: return false;
696: }
697: document.gradesub.submit();
698: }
699:
700: function reLoadList(formname) {
1.112 ng 701: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 702: formname.command.value = 'submission';
703: formname.submit();
704: }
1.45 ng 705: </script>
706: LISTJAVASCRIPT
707:
1.118 ng 708: &commonJSfunctions($request);
1.41 ng 709: $request->print($result);
1.39 ng 710:
1.401 albertel 711: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
712: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 713: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
714: "\n".$table.
1.401 albertel 715: ' <b>View Problem Text: </b><label><input type="radio" name="vProb" value="no" checked="checked" /> no </label>'."\n".
1.267 albertel 716: '<label><input type="radio" name="vProb" value="yes" /> one student </label>'."\n".
717: '<label><input type="radio" name="vProb" value="all" /> all students </label><br />'."\n".
718: ' <b>View Answer: </b><label><input type="radio" name="vAns" value="no" /> no </label>'."\n".
719: '<label><input type="radio" name="vAns" value="yes" /> one student </label>'."\n".
1.401 albertel 720: '<label><input type="radio" name="vAns" value="all" checked="checked" /> all students </label><br />'."\n".
1.49 albertel 721: ' <b>Submissions: </b>'."\n";
1.257 albertel 722: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.267 albertel 723: $gradeTable.='<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only </label>'."\n";
1.49 albertel 724: }
1.110 ng 725:
1.257 albertel 726: my $saveStatus = $env{'form.Status'} eq '' ? 'Active' : $env{'form.Status'};
727: $env{'form.Status'} = $saveStatus;
1.110 ng 728:
1.267 albertel 729: $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n".
730: '<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n".
731: '<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n".
1.348 bowersj2 732: '<label><input type="radio" name="lastSub" value="all" /> all details</label><br />'."\n".
733: ' <b>Grading Increments:</b> <select name="increment">'.
734: '<option value="1">Whole Points</option>'.
735: '<option value=".5">Half Points</option>'.
1.349 albertel 736: '<option value=".25">Quarter Points</option>'.
737: '<option value=".1">Tenths of a Point</option>'.
1.348 bowersj2 738: '</select>'.
739:
1.45 ng 740: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
741: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 742: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
743: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
744: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
745: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 746: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 747: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
748:
1.257 albertel 749: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
750: $gradeTable.='<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 751: } else {
752: $gradeTable.='<b>Student Status:</b> '.
753: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
754: }
1.112 ng 755:
1.126 ng 756: $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
757: 'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110 ng 758: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 759:
760: # checkall buttons
761: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 762: $gradeTable.='<input type="button" '."\n".
1.45 ng 763: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.249 albertel 764: 'value="Next->" /> <br />'."\n";
765: $gradeTable.=&check_buttons();
1.401 albertel 766: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="checked" />Check For Plagiarism</label>';
1.249 albertel 767: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1');
1.45 ng 768: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110 ng 769: '<table border="0"><tr bgcolor="#e6ffff">';
770: my $loop = 0;
771: while ($loop < 2) {
1.126 ng 772: $gradeTable.='<td><b> No.</b> </td><td><b> Select </b></td>'.
1.250 albertel 773: '<td>'.&nameUserString('header').' Section/Group</td>';
1.301 albertel 774: if ($env{'form.showgrading'} eq 'yes'
775: && $submitonly ne 'queued'
776: && $submitonly ne 'all') {
1.110 ng 777: foreach (sort(@$partlist)) {
1.324 albertel 778: my $display_part=&get_display_part((split(/_/))[0],$symb);
1.207 albertel 779: $gradeTable.='<td><b> Part: '.$display_part.
780: ' Status </b></td>';
1.110 ng 781: }
1.301 albertel 782: } elsif ($submitonly eq 'queued') {
783: $gradeTable.='<td><b> '.&mt('Queue Status').' </b></td>';
1.110 ng 784: }
785: $loop++;
1.126 ng 786: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 787: }
1.45 ng 788: $gradeTable.='</tr>'."\n";
1.41 ng 789:
1.45 ng 790: my $ctr = 0;
1.294 albertel 791: foreach my $student (sort
792: {
793: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
794: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
795: }
796: return $a cmp $b;
797: }
798: (keys(%$fullname))) {
1.41 ng 799: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 800:
1.110 ng 801: my %status = ();
1.301 albertel 802:
803: if ($submitonly eq 'queued') {
804: my %queue_status =
805: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
806: $udom,$uname);
807: next if (!defined($queue_status{'gradingqueue'}));
808: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
809: }
810:
811: if ($env{'form.showgrading'} eq 'yes'
812: && $submitonly ne 'queued'
813: && $submitonly ne 'all') {
1.324 albertel 814: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 815: my $submitted = 0;
1.164 albertel 816: my $graded = 0;
1.248 albertel 817: my $incorrect = 0;
1.110 ng 818: foreach (keys(%status)) {
1.145 albertel 819: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 820: $graded = 1 if ($status{$_} =~ /^ungraded/);
821: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
822:
1.110 ng 823: my ($foo,$partid,$foo1) = split(/\./,$_);
824: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 825: $submitted = 0;
1.150 albertel 826: my ($part)=split(/\./,$partid);
1.110 ng 827: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 828: $student.':'.$part.':submitted_by" value="'.
1.110 ng 829: $status{'resource.'.$partid.'.submitted_by'}.'" />';
830: }
1.41 ng 831: }
1.248 albertel 832:
1.156 albertel 833: next if (!$submitted && ($submitonly eq 'yes' ||
834: $submitonly eq 'incorrect' ||
835: $submitonly eq 'graded'));
1.248 albertel 836: next if (!$graded && ($submitonly eq 'graded'));
837: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 838: }
1.34 ng 839:
1.45 ng 840: $ctr++;
1.249 albertel 841: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
842:
1.104 albertel 843: if ( $perm{'vgr'} eq 'F' ) {
1.110 ng 844: $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126 ng 845: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 846: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
847: $student.':'.$$fullname{$student}.':::SECTION'.$section.
848: ') " /> </label></td>'."\n".'<td>'.
849: &nameUserString(undef,$$fullname{$student},$uname,$udom).
850: ' '.$section.'</td>'."\n";
1.110 ng 851:
1.257 albertel 852: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.110 ng 853: foreach (sort keys(%status)) {
854: next if (/^resource.*?submitted_by$/);
1.276 albertel 855: $gradeTable.='<td align="center"> '.$status{$_}.' </td>'."\n";
1.110 ng 856: }
1.41 ng 857: }
1.126 ng 858: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110 ng 859: $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41 ng 860: }
861: }
1.110 ng 862: if ($ctr%2 ==1) {
1.126 ng 863: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 864: if ($env{'form.showgrading'} eq 'yes'
865: && $submitonly ne 'queued'
866: && $submitonly ne 'all') {
1.110 ng 867: foreach (@$partlist) {
868: $gradeTable.='<td> </td>';
869: }
1.301 albertel 870: } elsif ($submitonly eq 'queued') {
871: $gradeTable.='<td> </td>';
1.110 ng 872: }
873: $gradeTable.='</tr>';
874: }
875:
1.249 albertel 876: $gradeTable.='</table></td></tr></table>'."\n".
1.45 ng 877: '<input type="button" '.
878: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126 ng 879: 'value="Next->" /></form>'."\n";
1.45 ng 880: if ($ctr == 0) {
1.96 albertel 881: my $num_students=(scalar(keys(%$fullname)));
882: if ($num_students eq 0) {
1.398 albertel 883: $gradeTable='<br /> <span class="LC_warning">There are no students currently enrolled.</span>';
1.96 albertel 884: } else {
1.171 albertel 885: my $submissions='submissions';
886: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
887: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 888: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 889: $gradeTable='<br /> <span class="LC_warning">'.
1.171 albertel 890: 'No '.$submissions.' found for this resource for any students. ('.$num_students.
1.398 albertel 891: ' students checked for '.$submissions.')</span><br />';
1.96 albertel 892: }
1.46 ng 893: } elsif ($ctr == 1) {
894: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 895: }
1.324 albertel 896: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 897: $request->print($gradeTable);
1.44 ng 898: return '';
1.10 ng 899: }
900:
1.44 ng 901: #---- Called from the listStudents routine
1.249 albertel 902:
903: sub check_script {
904: my ($form, $type)=@_;
905: my $chkallscript='<script type="text/javascript">
906: function checkall() {
907: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
908: ele = document.forms.'.$form.'.elements[i];
909: if (ele.name == "'.$type.'") {
910: document.forms.'.$form.'.elements[i].checked=true;
911: }
912: }
913: }
914:
915: function checksec() {
916: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
917: ele = document.forms.'.$form.'.elements[i];
918: string = document.forms.'.$form.'.chksec.value;
919: if
920: (ele.value.indexOf(":::SECTION"+string)>0) {
921: document.forms.'.$form.'.elements[i].checked=true;
922: }
923: }
924: }
925:
926:
927: function uncheckall() {
928: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
929: ele = document.forms.'.$form.'.elements[i];
930: if (ele.name == "'.$type.'") {
931: document.forms.'.$form.'.elements[i].checked=false;
932: }
933: }
934: }
935:
936: </script>'."\n";
937: return $chkallscript;
938: }
939:
940: sub check_buttons {
941: my $buttons.='<input type="button" onclick="checkall()" value="Check All" />';
942: $buttons.='<input type="button" onclick="uncheckall()" value="Uncheck All" /> ';
943: $buttons.='<input type="button" onclick="checksec()" value="Check Section/Group" />';
944: $buttons.='<input type="text" size="5" name="chksec" /> ';
945: return $buttons;
946: }
947:
1.44 ng 948: # Displays the submissions for one student or a group of students
1.34 ng 949: sub processGroup {
1.41 ng 950: my ($request) = shift;
951: my $ctr = 0;
1.155 albertel 952: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 953: my $total = scalar(@stuchecked)-1;
1.45 ng 954:
1.396 banghart 955: foreach my $student (@stuchecked) {
956: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 957: $env{'form.student'} = $uname;
958: $env{'form.userdom'} = $udom;
959: $env{'form.fullname'} = $fullname;
1.41 ng 960: &submission($request,$ctr,$total);
961: $ctr++;
962: }
963: return '';
1.35 ng 964: }
1.34 ng 965:
1.44 ng 966: #------------------------------------------------------------------------------------
967: #
968: #-------------------------- Next few routines handles grading by student, essentially
969: # handles essay response type problem/part
970: #
971: #--- Javascript to handle the submission page functionality ---
972: sub sub_page_js {
973: my $request = shift;
974: $request->print(<<SUBJAVASCRIPT);
975: <script type="text/javascript" language="javascript">
1.71 ng 976: function updateRadio(formname,id,weight) {
1.125 ng 977: var gradeBox = formname["GD_BOX"+id];
978: var radioButton = formname["RADVAL"+id];
979: var oldpts = formname["oldpts"+id].value;
1.72 ng 980: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 981: gradeBox.value = pts;
982: var resetbox = false;
983: if (isNaN(pts) || pts < 0) {
984: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
985: for (var i=0; i<radioButton.length; i++) {
986: if (radioButton[i].checked) {
987: gradeBox.value = i;
988: resetbox = true;
989: }
990: }
991: if (!resetbox) {
992: formtextbox.value = "";
993: }
994: return;
1.44 ng 995: }
1.71 ng 996:
997: if (pts > weight) {
998: var resp = confirm("You entered a value ("+pts+
999: ") greater than the weight for the part. Accept?");
1000: if (resp == false) {
1.125 ng 1001: gradeBox.value = oldpts;
1.71 ng 1002: return;
1003: }
1.44 ng 1004: }
1.13 albertel 1005:
1.71 ng 1006: for (var i=0; i<radioButton.length; i++) {
1007: radioButton[i].checked=false;
1008: if (pts == i && pts != "") {
1009: radioButton[i].checked=true;
1010: }
1011: }
1012: updateSelect(formname,id);
1.125 ng 1013: formname["stores"+id].value = "0";
1.41 ng 1014: }
1.5 albertel 1015:
1.72 ng 1016: function writeBox(formname,id,pts) {
1.125 ng 1017: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1018: if (checkSolved(formname,id) == 'update') {
1019: gradeBox.value = pts;
1020: } else {
1.125 ng 1021: var oldpts = formname["oldpts"+id].value;
1.72 ng 1022: gradeBox.value = oldpts;
1.125 ng 1023: var radioButton = formname["RADVAL"+id];
1.71 ng 1024: for (var i=0; i<radioButton.length; i++) {
1025: radioButton[i].checked=false;
1.72 ng 1026: if (i == oldpts) {
1.71 ng 1027: radioButton[i].checked=true;
1028: }
1029: }
1.41 ng 1030: }
1.125 ng 1031: formname["stores"+id].value = "0";
1.71 ng 1032: updateSelect(formname,id);
1033: return;
1.41 ng 1034: }
1.44 ng 1035:
1.71 ng 1036: function clearRadBox(formname,id) {
1037: if (checkSolved(formname,id) == 'noupdate') {
1038: updateSelect(formname,id);
1039: return;
1040: }
1.125 ng 1041: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1042: for (var i=0; i<gradeSelect.length; i++) {
1043: if (gradeSelect[i].selected) {
1044: var selectx=i;
1045: }
1046: }
1.125 ng 1047: var stores = formname["stores"+id];
1.71 ng 1048: if (selectx == stores.value) { return };
1.125 ng 1049: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1050: gradeBox.value = "";
1.125 ng 1051: var radioButton = formname["RADVAL"+id];
1.71 ng 1052: for (var i=0; i<radioButton.length; i++) {
1053: radioButton[i].checked=false;
1054: }
1055: stores.value = selectx;
1056: }
1.5 albertel 1057:
1.71 ng 1058: function checkSolved(formname,id) {
1.125 ng 1059: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1060: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1061: if (!reply) {return "noupdate";}
1.120 ng 1062: formname.overRideScore.value = 'yes';
1.41 ng 1063: }
1.71 ng 1064: return "update";
1.13 albertel 1065: }
1.71 ng 1066:
1067: function updateSelect(formname,id) {
1.125 ng 1068: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1069: return;
1.41 ng 1070: }
1.33 ng 1071:
1.121 ng 1072: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1073: function checksubmit(formname,val,total,parttot) {
1.121 ng 1074: formname.gradeOpt.value = val;
1.71 ng 1075: if (val == "Save & Next") {
1076: for (i=0;i<=total;i++) {
1077: for (j=0;j<parttot;j++) {
1.125 ng 1078: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1079: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1080: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1081: if (points == "") {
1.125 ng 1082: var name = formname["name"+i].value;
1.129 ng 1083: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1084: var resp = confirm("You did not assign a score for "+studentID+
1085: ", part "+partid+". Continue?");
1.71 ng 1086: if (resp == false) {
1.125 ng 1087: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1088: return false;
1089: }
1090: }
1091: }
1092:
1093: }
1094: }
1095:
1096: }
1.121 ng 1097: if (val == "Grade Student") {
1098: formname.showgrading.value = "yes";
1099: if (formname.Status.value == "") {
1100: formname.Status.value = "Active";
1101: }
1102: formname.studentNo.value = total;
1103: }
1.120 ng 1104: formname.submit();
1105: }
1106:
1.71 ng 1107: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1108: function checkSubmitPage(formname,total) {
1109: noscore = new Array(100);
1110: var ptr = 0;
1111: for (i=1;i<total;i++) {
1.125 ng 1112: var partid = formname["q_"+i].value;
1.127 ng 1113: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1114: var points = formname["GD_BOX"+i+"_"+partid].value;
1115: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1116: if (points == "" && status != "correct_by_student") {
1117: noscore[ptr] = i;
1118: ptr++;
1119: }
1120: }
1121: }
1122: if (ptr != 0) {
1123: var sense = ptr == 1 ? ": " : "s: ";
1124: var prolist = "";
1125: if (ptr == 1) {
1126: prolist = noscore[0];
1127: } else {
1128: var i = 0;
1129: while (i < ptr-1) {
1130: prolist += noscore[i]+", ";
1131: i++;
1132: }
1133: prolist += "and "+noscore[i];
1134: }
1135: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1136: if (resp == false) {
1137: return false;
1138: }
1139: }
1.45 ng 1140:
1.71 ng 1141: formname.submit();
1142: }
1143: </script>
1144: SUBJAVASCRIPT
1145: }
1.45 ng 1146:
1.71 ng 1147: #--- javascript for essay type problem --
1148: sub sub_page_kw_js {
1149: my $request = shift;
1.80 ng 1150: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1151: &commonJSfunctions($request);
1.350 albertel 1152:
1.351 albertel 1153: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1154: <script text="text/javascript">
1155: function checkInput() {
1156: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1157: var nmsg = opener.document.SCORE.savemsgN.value;
1158: var usrctr = document.msgcenter.usrctr.value;
1159: var newval = opener.document.SCORE["newmsg"+usrctr];
1160: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1161:
1162: var msgchk = "";
1163: if (document.msgcenter.subchk.checked) {
1164: msgchk = "msgsub,";
1165: }
1166: var includemsg = 0;
1167: for (var i=1; i<=nmsg; i++) {
1168: var opnmsg = opener.document.SCORE["savemsg"+i];
1169: var frmmsg = document.msgcenter["msg"+i];
1170: opnmsg.value = opener.checkEntities(frmmsg.value);
1171: var showflg = opener.document.SCORE["shownOnce"+i];
1172: showflg.value = "1";
1173: var chkbox = document.msgcenter["msgn"+i];
1174: if (chkbox.checked) {
1175: msgchk += "savemsg"+i+",";
1176: includemsg = 1;
1177: }
1178: }
1179: if (document.msgcenter.newmsgchk.checked) {
1180: msgchk += "newmsg"+usrctr;
1181: includemsg = 1;
1182: }
1183: imgformname = opener.document.SCORE["mailicon"+usrctr];
1184: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1185: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1186: includemsg.value = msgchk;
1187:
1188: self.close()
1189:
1190: }
1191: </script>
1192: INNERJS
1193:
1.351 albertel 1194: my $inner_js_highlight_central=<<INNERJS;
1195: <script type="text/javascript">
1196: function updateChoice(flag) {
1197: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1198: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1199: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1200: opener.document.SCORE.refresh.value = "on";
1201: if (opener.document.SCORE.keywords.value!=""){
1202: opener.document.SCORE.submit();
1203: }
1204: self.close()
1205: }
1206: </script>
1207: INNERJS
1208:
1209: my $start_page_msg_central =
1210: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1211: {'js_ready' => 1,
1212: 'only_body' => 1,
1213: 'bgcolor' =>'#FFFFFF',});
1214: my $end_page_msg_central =
1215: &Apache::loncommon::end_page({'js_ready' => 1});
1216:
1217:
1218: my $start_page_highlight_central =
1219: &Apache::loncommon::start_page('Highlight Central',
1220: $inner_js_highlight_central,
1.350 albertel 1221: {'js_ready' => 1,
1222: 'only_body' => 1,
1223: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1224: my $end_page_highlight_central =
1.350 albertel 1225: &Apache::loncommon::end_page({'js_ready' => 1});
1226:
1.219 www 1227: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1228: $docopen=~s/^document\.//;
1.71 ng 1229: $request->print(<<SUBJAVASCRIPT);
1230: <script type="text/javascript" language="javascript">
1.45 ng 1231:
1.44 ng 1232: //===================== Show list of keywords ====================
1.122 ng 1233: function keywords(formname) {
1234: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1235: if (nret==null) return;
1.122 ng 1236: formname.keywords.value = nret;
1.44 ng 1237:
1.122 ng 1238: if (formname.keywords.value != "") {
1.128 ng 1239: formname.refresh.value = "on";
1.122 ng 1240: formname.submit();
1.44 ng 1241: }
1242: return;
1243: }
1244:
1245: //===================== Script to view submitted by ==================
1246: function viewSubmitter(submitter) {
1247: document.SCORE.refresh.value = "on";
1248: document.SCORE.NCT.value = "1";
1249: document.SCORE.unamedom0.value = submitter;
1250: document.SCORE.submit();
1251: return;
1252: }
1253:
1254: //===================== Script to add keyword(s) ==================
1255: function getSel() {
1256: if (document.getSelection) txt = document.getSelection();
1257: else if (document.selection) txt = document.selection.createRange().text;
1258: else return;
1259: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1260: if (cleantxt=="") {
1.46 ng 1261: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 1262: return;
1263: }
1264: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1265: if (nret==null) return;
1.127 ng 1266: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1267: if (document.SCORE.keywords.value != "") {
1.127 ng 1268: document.SCORE.refresh.value = "on";
1.44 ng 1269: document.SCORE.submit();
1270: }
1271: return;
1272: }
1273:
1274: //====================== Script for composing message ==============
1.80 ng 1275: // preload images
1276: img1 = new Image();
1277: img1.src = "$iconpath/mailbkgrd.gif";
1278: img2 = new Image();
1279: img2.src = "$iconpath/mailto.gif";
1280:
1.44 ng 1281: function msgCenter(msgform,usrctr,fullname) {
1282: var Nmsg = msgform.savemsgN.value;
1283: savedMsgHeader(Nmsg,usrctr,fullname);
1284: var subject = msgform.msgsub.value;
1.127 ng 1285: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1286: re = /msgsub/;
1287: var shwsel = "";
1288: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1289: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1290: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1291: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1292: var testmsg = "savemsg"+i+",";
1293: re = new RegExp(testmsg,"g");
1.44 ng 1294: shwsel = "";
1295: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1296: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1297: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1298: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1299: //any < is already converted to <, etc. However, only once!!
1.44 ng 1300: }
1.125 ng 1301: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1302: shwsel = "";
1303: re = /newmsg/;
1304: if (re.test(msgchk)) { shwsel = "checked" }
1305: newMsg(newmsg,shwsel);
1306: msgTail();
1307: return;
1308: }
1309:
1.123 ng 1310: function checkEntities(strx) {
1311: if (strx.length == 0) return strx;
1312: var orgStr = ["&", "<", ">", '"'];
1313: var newStr = ["&", "<", ">", """];
1314: var counter = 0;
1315: while (counter < 4) {
1316: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1317: counter++;
1318: }
1319: return strx;
1320: }
1321:
1322: function strReplace(strx, orgStr, newStr) {
1323: return strx.split(orgStr).join(newStr);
1324: }
1325:
1.44 ng 1326: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1327: var height = 70*Nmsg+250;
1.44 ng 1328: var scrollbar = "no";
1329: if (height > 600) {
1330: height = 600;
1331: scrollbar = "yes";
1332: }
1.118 ng 1333: var xpos = (screen.width-600)/2;
1334: xpos = (xpos < 0) ? '0' : xpos;
1335: var ypos = (screen.height-height)/2-30;
1336: ypos = (ypos < 0) ? '0' : ypos;
1337:
1.206 albertel 1338: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1339: pWin.focus();
1340: pDoc = pWin.document;
1.219 www 1341: pDoc.$docopen;
1.351 albertel 1342: pDoc.write('$start_page_msg_central');
1.76 ng 1343:
1344: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1345: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.398 albertel 1346: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"</span></h3><br /><br />");
1.76 ng 1347:
1348: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1349: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1350: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 1351: }
1352: function displaySubject(msg,shwsel) {
1.76 ng 1353: pDoc = pWin.document;
1354: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1355: pDoc.write("<td>Subject</td>");
1356: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1357: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 1358: }
1359:
1.72 ng 1360: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1361: pDoc = pWin.document;
1362: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1363: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
1364: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1365: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 1366: }
1367:
1368: function newMsg(newmsg,shwsel) {
1.76 ng 1369: pDoc = pWin.document;
1370: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1371: pDoc.write("<td align=\\"center\\">New</td>");
1372: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1373: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 1374: }
1375:
1376: function msgTail() {
1.76 ng 1377: pDoc = pWin.document;
1378: pDoc.write("</table>");
1379: pDoc.write("</td></tr></table> ");
1380: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1381: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1382: pDoc.write("</form>");
1.351 albertel 1383: pDoc.write('$end_page_msg_central');
1.128 ng 1384: pDoc.close();
1.44 ng 1385: }
1386:
1387: //====================== Script for keyword highlight options ==============
1388: function kwhighlight() {
1389: var kwclr = document.SCORE.kwclr.value;
1390: var kwsize = document.SCORE.kwsize.value;
1391: var kwstyle = document.SCORE.kwstyle.value;
1392: var redsel = "";
1393: var grnsel = "";
1394: var blusel = "";
1395: if (kwclr=="red") {var redsel="checked"};
1396: if (kwclr=="green") {var grnsel="checked"};
1397: if (kwclr=="blue") {var blusel="checked"};
1398: var sznsel = "";
1399: var sz1sel = "";
1400: var sz2sel = "";
1401: if (kwsize=="0") {var sznsel="checked"};
1402: if (kwsize=="+1") {var sz1sel="checked"};
1403: if (kwsize=="+2") {var sz2sel="checked"};
1404: var synsel = "";
1405: var syisel = "";
1406: var sybsel = "";
1407: if (kwstyle=="") {var synsel="checked"};
1408: if (kwstyle=="<i>") {var syisel="checked"};
1409: if (kwstyle=="<b>") {var sybsel="checked"};
1410: highlightCentral();
1411: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1412: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1413: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1414: highlightend();
1415: return;
1416: }
1417:
1418: function highlightCentral() {
1.76 ng 1419: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1420: var xpos = (screen.width-400)/2;
1421: xpos = (xpos < 0) ? '0' : xpos;
1422: var ypos = (screen.height-330)/2-30;
1423: ypos = (ypos < 0) ? '0' : ypos;
1424:
1.206 albertel 1425: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1426: hwdWin.focus();
1427: var hDoc = hwdWin.document;
1.219 www 1428: hDoc.$docopen;
1.351 albertel 1429: hDoc.write('$start_page_highlight_central');
1.76 ng 1430: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.398 albertel 1431: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options</span></h3><br /><br />");
1.76 ng 1432:
1433: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1434: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1435: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 1436: }
1437:
1438: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1439: var hDoc = hwdWin.document;
1440: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1441: hDoc.write("<td align=\\"left\\">");
1442: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1443: hDoc.write("<td align=\\"left\\">");
1444: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1445: hDoc.write("<td align=\\"left\\">");
1446: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1447: hDoc.write("</tr>");
1.44 ng 1448: }
1449:
1450: function highlightend() {
1.76 ng 1451: var hDoc = hwdWin.document;
1452: hDoc.write("</table>");
1453: hDoc.write("</td></tr></table> ");
1454: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1455: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1456: hDoc.write("</form>");
1.351 albertel 1457: hDoc.write('$end_page_highlight_central');
1.128 ng 1458: hDoc.close();
1.44 ng 1459: }
1460:
1461: </script>
1462: SUBJAVASCRIPT
1463: }
1464:
1.349 albertel 1465: sub get_increment {
1.348 bowersj2 1466: my $increment = $env{'form.increment'};
1467: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1468: $increment != .1) {
1469: $increment = 1;
1470: }
1471: return $increment;
1472: }
1473:
1.71 ng 1474: #--- displays the grading box, used in essay type problem and grading by page/sequence
1475: sub gradeBox {
1.322 albertel 1476: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1477: my $checkIcon = '<img alt="'.&mt('Check Mark').
1478: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 1479: '/check.gif" height="16" border="0" />';
1480: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1481: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1.398 albertel 1482: '<span class="LC_info">problem weight assigned by computer</span>');
1.71 ng 1483: $wgt = ($wgt > 0 ? $wgt : '1');
1484: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1485: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1486: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.324 albertel 1487: my $display_part=&get_display_part($partid,$symb);
1.270 albertel 1488: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1489: [$partid]);
1490: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1491: if ($last_resets{$partid}) {
1492: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1493: }
1.71 ng 1494: $result.='<table border="0"><tr><td>'.
1.207 albertel 1495: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1496: my $ctr = 0;
1.348 bowersj2 1497: my $thisweight = 0;
1.349 albertel 1498: my $increment = &get_increment();
1.71 ng 1499: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1500: while ($thisweight<=$wgt) {
1.381 albertel 1501: $result.= '<td><span style="white-space: nowrap;"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1502: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1503: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1504: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.71 ng 1505: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1506: $thisweight += $increment;
1.71 ng 1507: $ctr++;
1508: }
1509: $result.='</tr></table>';
1510: $result.='</td><td> <b>or</b> </td>'."\n";
1511: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1512: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1513: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1514: $wgt.')" /></td>'."\n";
1515: $result.='<td>/'.$wgt.' '.$wgtmsg.
1516: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1517: ' </td><td>'."\n";
1518: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1519: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1520: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.384 albertel 1521: $result.='<option></option>'.
1.401 albertel 1522: '<option selected="selected">excused</option>';
1.71 ng 1523: } else {
1.401 albertel 1524: $result.='<option selected="selected"></option>'.
1.125 ng 1525: '<option>excused</option>';
1.71 ng 1526: }
1.125 ng 1527: $result.='<option>reset status</option></select>'."\n";
1.381 albertel 1528: $result.=" \n";
1.71 ng 1529: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1530: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1531: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1532: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1533: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1534: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1535: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1536: $aggtries.'" />'."\n";
1.71 ng 1537: $result.='</td></tr></table>'."\n";
1.323 banghart 1538: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1539: return $result;
1540: }
1.322 albertel 1541:
1542: sub handback_box {
1.323 banghart 1543: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1544: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1545: my (@respids);
1.375 albertel 1546: my @part_response_id = &flatten_responseType($responseType);
1547: foreach my $part_response_id (@part_response_id) {
1548: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1549: if ($part eq $partid) {
1.375 albertel 1550: push(@respids,$resp);
1.323 banghart 1551: }
1552: }
1.318 banghart 1553: my $result;
1.323 banghart 1554: foreach my $respid (@respids) {
1.322 albertel 1555: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1556: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1557: next if (!@$files);
1558: my $file_counter = 1;
1.313 banghart 1559: foreach my $file (@$files) {
1.368 banghart 1560: if ($file =~ /\/portfolio\//) {
1561: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1562: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1563: $file_disp = "$name.$ext";
1564: $file = $file_path.$file_disp;
1565: $result.=&mt('Return commented version of [_1] to student.',
1566: '<span class="LC_filename">'.$file_disp.'</span>');
1567: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1568: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.369 banghart 1569: $result.='(File will be uploaded when you click on Save & Next below.)<br />';
1.368 banghart 1570: $file_counter++;
1571: }
1.322 albertel 1572: }
1.313 banghart 1573: }
1.318 banghart 1574: return $result;
1.71 ng 1575: }
1.44 ng 1576:
1.58 albertel 1577: sub show_problem {
1.382 albertel 1578: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1579: my $rendered;
1.382 albertel 1580: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1581: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1582: if ($mode eq 'both' or $mode eq 'text') {
1583: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1584: $env{'request.course.id'},
1585: undef,\%form);
1.144 albertel 1586: }
1.58 albertel 1587: if ($removeform) {
1588: $rendered=~s|<form(.*?)>||g;
1589: $rendered=~s|</form>||g;
1.374 albertel 1590: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1591: }
1.144 albertel 1592: my $companswer;
1593: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1594: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1595: $companswer=
1596: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1597: $env{'request.course.id'},
1598: %form);
1.144 albertel 1599: }
1.58 albertel 1600: if ($removeform) {
1601: $companswer=~s|<form(.*?)>||g;
1602: $companswer=~s|</form>||g;
1.144 albertel 1603: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1604: }
1605: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1606: $result.='<table border="0" width="100%">';
1.144 albertel 1607: if ($viewon) {
1608: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1609: if ($mode eq 'both' or $mode eq 'text') {
1610: $result.='View of the problem - ';
1611: } else {
1612: $result.='Correct answer: ';
1613: }
1.257 albertel 1614: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1615: }
1616: if ($mode eq 'both') {
1617: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1618: $result.='<b>Correct answer:</b><br />'.$companswer;
1619: } elsif ($mode eq 'text') {
1620: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1621: } elsif ($mode eq 'answer') {
1622: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1623: }
1.58 albertel 1624: $result.='</td></tr></table>';
1625: $result.='</td></tr></table><br />';
1.71 ng 1626: return $result;
1.58 albertel 1627: }
1.397 albertel 1628:
1.396 banghart 1629: sub files_exist {
1630: my ($r, $symb) = @_;
1631: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1632:
1.396 banghart 1633: foreach my $student (@students) {
1634: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1635: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1636: $udom,$uname);
1.396 banghart 1637: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1638: foreach my $submission (@$string) {
1639: my ($partid,$respid) =
1640: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1641: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1642: \%record);
1643: return 1 if (@$files);
1.396 banghart 1644: }
1645: }
1.397 albertel 1646: return 0;
1.396 banghart 1647: }
1.397 albertel 1648:
1.394 banghart 1649: sub download_all_link {
1650: my ($r,$symb) = @_;
1.395 albertel 1651: my $all_students =
1652: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1653:
1654: my $parts =
1655: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1656:
1.394 banghart 1657: my $identifier = &Apache::loncommon::get_cgi_id();
1658: &Apache::lonnet::appenv('cgi.'.$identifier.'.students' => $all_students,
1659: 'cgi.'.$identifier.'.symb' => $symb,
1.395 albertel 1660: 'cgi.'.$identifier.'.parts' => $parts,);
1661: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1662: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1663: return
1664: }
1.395 albertel 1665:
1.44 ng 1666: # --------------------------- show submissions of a student, option to grade
1667: sub submission {
1668: my ($request,$counter,$total) = @_;
1669:
1.257 albertel 1670: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1671: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1672: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1673: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1674:
1.324 albertel 1675: my $symb = &get_symb($request);
1676: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1677:
1678: if (!&canview($usec)) {
1.398 albertel 1679: $request->print('<span class="LC_warning">Unable to view requested student.('.
1680: $uname.':'.$udom.' in section '.$usec.' in course id '.
1681: $env{'request.course.id'}.')</span>');
1.324 albertel 1682: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1683: return;
1684: }
1685:
1.257 albertel 1686: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1687: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1688: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1689: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1690: my $checkIcon = '<img alt="'.&mt('Check Mark').
1691: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1692: '/check.gif" height="16" border="0" />';
1.41 ng 1693:
1694: # header info
1695: if ($counter == 0) {
1696: &sub_page_js($request);
1.257 albertel 1697: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1698: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1699: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1700: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1701: &download_all_link($request, $symb);
1702: }
1.398 albertel 1703: $request->print('<h3> <span class="LC_info">Submission Record</span></h3>'."\n".
1704: '<h4> <b>Resource: </b>'.$env{'form.probTitle'}.'</h4>'."\n");
1.118 ng 1705:
1.257 albertel 1706: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1707: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1708: $checkIcon.' symbol.'."\n";
1709: $request->print($checkMark);
1710: }
1.41 ng 1711:
1.44 ng 1712: # option to display problem, only once else it cause problems
1713: # with the form later since the problem has a form.
1.257 albertel 1714: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1715: my $mode;
1.257 albertel 1716: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1717: $mode='both';
1.257 albertel 1718: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1719: $mode='text';
1.257 albertel 1720: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1721: $mode='answer';
1722: }
1.329 albertel 1723: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1724: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1725: }
1726:
1.44 ng 1727: # kwclr is the only variable that is guaranteed to be non blank
1728: # if this subroutine has been called once.
1.41 ng 1729: my %keyhash = ();
1.257 albertel 1730: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1731: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1732: $env{'course.'.$env{'request.course.id'}.'.domain'},
1733: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1734:
1.257 albertel 1735: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1736: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1737: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1738: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1739: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1740: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1741: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1742: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1743: }
1.257 albertel 1744: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1745:
1.303 banghart 1746: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1747: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1748: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1749: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1750: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1751: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1752: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1753: '<input type="hidden" name="studentNo" value="" />'."\n".
1754: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1755: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1756: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1757: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1758: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1759: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.326 albertel 1760: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
1761: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1762: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1763: '<input type="hidden" name="NCT"'.
1.257 albertel 1764: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1765: if ($env{'form.handgrade'} eq 'yes') {
1766: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1767: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1768: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1769: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1770: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1771: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1772: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1773: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1774: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1775: }
1.123 ng 1776: }
1.41 ng 1777:
1778: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1779: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1780: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1781: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1782: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1783: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1784: '" />'."\n".
1785: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1786: $cts++;
1787: }
1788: $request->print($prnmsg);
1.32 ng 1789:
1.257 albertel 1790: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1791: #
1792: # Print out the keyword options line
1793: #
1.41 ng 1794: $request->print(<<KEYWORDS);
1.38 ng 1795: <b>Keyword Options:</b>
1.417 albertel 1796: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.38 ng 1797: <a href="#" onMouseDown="javascript:getSel(); return false"
1798: CLASS="page">Paste Selection to List</a>
1.417 albertel 1799: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 1800: KEYWORDS
1.88 www 1801: #
1802: # Load the other essays for similarity check
1803: #
1.324 albertel 1804: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 1805: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 1806: $apath=&escape($apath);
1.88 www 1807: $apath=~s/\W/\_/gs;
1808: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1809: }
1810: }
1.44 ng 1811:
1.257 albertel 1812: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1813: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1814: my $mode;
1.257 albertel 1815: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1816: $mode='both';
1.257 albertel 1817: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1818: $mode='text';
1.257 albertel 1819: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1820: $mode='answer';
1821: }
1.329 albertel 1822: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1823: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1824: }
1.144 albertel 1825:
1.257 albertel 1826: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1827: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1828:
1.44 ng 1829: # Display student info
1.41 ng 1830: $request->print(($counter == 0 ? '' : '<br />'));
1.326 albertel 1831: my $result='<table border="0" width="100%"><tr><td bgcolor="#777777">'."\n".
1832: '<table border="0" width="100%"><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1833:
1.257 albertel 1834: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1835: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1836: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1837:
1.118 ng 1838: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1839: my @col_fullnames;
1.56 matthew 1840: my ($classlist,$fullname);
1.257 albertel 1841: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1842: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1843: for (keys (%$handgrade)) {
1.44 ng 1844: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1845: '.maxcollaborators',
1846: $symb,$udom,$uname);
1847: next if ($ncol <= 0);
1848: s/\_/\./g;
1849: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1850: my @goodcollaborators = ();
1851: my @badcollaborators = ();
1852: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1853: $_ =~ s/[\$\^\(\)]//g;
1854: next if ($_ eq '');
1.80 ng 1855: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1856: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1857: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1858: # Doing this grep allows 'fuzzy' specification
1859: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1860: if (! scalar(@Matches)) {
1861: push @badcollaborators,$_;
1862: } else {
1863: push @goodcollaborators, @Matches;
1864: }
1.80 ng 1865: }
1.86 ng 1866: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1867: $result.='<b>Collaborators: </b>';
1.86 ng 1868: foreach (@goodcollaborators) {
1869: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1870: push @col_fullnames, $givenn.' '.$lastname;
1871: $result.=$$fullname{$_}.' ';
1872: }
1.57 matthew 1873: $result.='<br />'."\n";
1.150 albertel 1874: my ($part)=split(/\./,$_);
1.86 ng 1875: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1876: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1877: "\n";
1.86 ng 1878: }
1879: if (scalar(@badcollaborators) > 0) {
1880: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1881: $result.='This student has submitted ';
1882: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1883: $result .= ': '.join(', ',@badcollaborators);
1884: $result .= '</td></tr></table>';
1885: }
1886: if (scalar(@badcollaborators > $ncol)) {
1887: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1888: $result .= 'This student has submitted too many '.
1889: 'collaborators. Maximum is '.$ncol.'.';
1890: $result .= '</td></tr></table>';
1891: }
1.41 ng 1892: }
1893: }
1.44 ng 1894: $request->print($result."\n");
1.33 ng 1895:
1.44 ng 1896: # print student answer/submission
1897: # Options are (1) Handgaded submission only
1898: # (2) Last submission, includes submission that is not handgraded
1899: # (for multi-response type part)
1900: # (3) Last submission plus the parts info
1901: # (4) The whole record for this student
1.257 albertel 1902: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1903: my ($string,$timestamp)= &get_last_submission(\%record);
1904: my $lastsubonly=''.
1905: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1906: $$timestamp)."</td></tr>\n";
1907: if ($$timestamp eq '') {
1908: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1909: } else {
1910: my %seenparts;
1.375 albertel 1911: my @part_response_id = &flatten_responseType($responseType);
1912: foreach my $part (@part_response_id) {
1.393 albertel 1913: next if ($env{'form.lastSub'} eq 'hdgrade'
1914: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
1915:
1.375 albertel 1916: my ($partid,$respid) = @{ $part };
1.324 albertel 1917: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 1918: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1919: if (exists($seenparts{$partid})) { next; }
1920: $seenparts{$partid}=1;
1.207 albertel 1921: my $submitby='<b>Part:</b> '.$display_part.
1922: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1923: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1924: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 1925: '\');" target="_self">'.
1.257 albertel 1926: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1927: $request->print($submitby);
1928: next;
1929: }
1930: my $responsetype = $responseType->{$partid}->{$respid};
1931: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1932: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1.398 albertel 1933: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1934: ' )</span> '.
1935: '<span class="LC_warning">Nothing submitted - no attempts</span><br /><br />';
1.151 albertel 1936: next;
1937: }
1938: foreach (@$string) {
1939: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1.375 albertel 1940: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.151 albertel 1941: my ($ressub,$subval) = split(/:/,$_,2);
1942: # Similarity check
1943: my $similar='';
1.257 albertel 1944: if($env{'form.checkPlag'}){
1.151 albertel 1945: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1946: &most_similar($uname,$udom,$subval);
1947: if ($osim) {
1948: $osim=int($osim*100.0);
1.398 albertel 1949: $similar="<hr /><h3><span class=\"LC_warning\">Essay".
1.151 albertel 1950: " is $osim% similar to an essay by ".
1951: &Apache::loncommon::plainname($oname,$odom).
1.398 albertel 1952: '</span></h3><blockquote><i>'.
1.151 albertel 1953: &keywords_highlight($oessay).
1954: '</i></blockquote><hr />';
1955: }
1.150 albertel 1956: }
1.151 albertel 1957: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1958: if ($env{'form.lastSub'} eq 'lastonly' ||
1959: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 1960: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 1961: my $display_part=&get_display_part($partid,$symb);
1.403 albertel 1962: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1963: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1.398 albertel 1964: ' )</span> ';
1.313 banghart 1965: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1966: if (@$files) {
1.398 albertel 1967: $lastsubonly.='<br /><span class="LC_warning">Like all files provided by users, this file may contain virusses</span><br />';
1.303 banghart 1968: my $file_counter = 0;
1.313 banghart 1969: foreach my $file (@$files) {
1.303 banghart 1970: $file_counter ++;
1.232 albertel 1971: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 1972: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 1973: }
1.236 albertel 1974: $lastsubonly.='<br />';
1.41 ng 1975: }
1.151 albertel 1976: $lastsubonly.='<b>Submitted Answer: </b>'.
1977: &cleanRecord($subval,$responsetype,$symb,$partid,
1978: $respid,\%record,$order);
1979: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1980: }
1981: }
1982: }
1.151 albertel 1983: }
1984: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1985: $request->print($lastsubonly);
1.257 albertel 1986: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 1987: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 1988: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1989: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1990: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1991: $env{'request.course.id'},
1.44 ng 1992: $last,'.submission',
1993: 'Apache::grades::keywords_highlight'));
1.41 ng 1994: }
1.120 ng 1995:
1.121 ng 1996: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1997: .$udom.'" />'."\n");
1.41 ng 1998:
1.44 ng 1999: # return if view submission with no grading option
1.257 albertel 2000: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2001: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2002: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2003: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.169 albertel 2004: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 2005: if (($env{'form.command'} eq 'submission') ||
2006: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2007: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2008: }
1.180 albertel 2009: $request->print($toGrade);
1.41 ng 2010: return;
1.180 albertel 2011: } else {
2012: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 2013: }
1.33 ng 2014:
1.121 ng 2015: # essay grading message center
1.257 albertel 2016: if ($env{'form.handgrade'} eq 'yes') {
2017: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2018: my $msgfor = $givenn.' '.$lastname;
2019: if (scalar(@col_fullnames) > 0) {
2020: my $lastone = pop @col_fullnames;
2021: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
2022: }
2023: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 2024: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
2025: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2026: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2027: ',\''.$msgfor.'\');" target="_self">'.
1.350 albertel 2028: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
2029: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2030: '<img src="'.$request->dir_config('lonIconsURL').
2031: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2032: '<br /> ('.
2033: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 2034: $request->print($result);
1.118 ng 2035: }
1.300 albertel 2036: if ($perm{'vgr'}) {
1.297 www 2037: $request->print('<br />'.
1.300 albertel 2038: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2039: $uname,$udom,'check'));
1.297 www 2040: }
1.300 albertel 2041: if ($perm{'opa'}) {
1.297 www 2042: $request->print('<br />'.
1.300 albertel 2043: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2044: $uname,$udom,$symb,'check'));
1.297 www 2045: }
1.41 ng 2046:
2047: my %seen = ();
2048: my @partlist;
1.129 ng 2049: my @gradePartRespid;
1.375 albertel 2050: my @part_response_id = &flatten_responseType($responseType);
2051: foreach my $part_response_id (@part_response_id) {
2052: my ($partid,$respid) = @{ $part_response_id };
2053: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2054: next if ($seen{$partid} > 0);
1.41 ng 2055: $seen{$partid}++;
1.393 albertel 2056: next if ($$handgrade{$part_resp} ne 'yes'
2057: && $env{'form.lastSub'} eq 'hdgrade');
1.41 ng 2058: push @partlist,$partid;
1.129 ng 2059: push @gradePartRespid,$partid.'.'.$respid;
1.322 albertel 2060: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2061: }
1.45 ng 2062: $result='<input type="hidden" name="partlist'.$counter.
2063: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2064: $result.='<input type="hidden" name="gradePartRespid'.
2065: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2066: my $ctr = 0;
2067: while ($ctr < scalar(@partlist)) {
2068: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2069: $partlist[$ctr].'" />'."\n";
2070: $ctr++;
2071: }
2072: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 2073:
2074: # print end of form
2075: if ($counter == $total) {
1.297 www 2076: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 2077: $endform.='<input type="button" value="Save & Next" '.
2078: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2079: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2080: my $ntstu ='<select name="NTSTU">'.
2081: '<option>1</option><option>2</option>'.
2082: '<option>3</option><option>5</option>'.
2083: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2084: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2085: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.119 ng 2086: $endform.=$ntstu.'student(s) ';
1.126 ng 2087: $endform.='<input type="button" value="Previous" '.
1.417 albertel 2088: 'onClick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.126 ng 2089: '<input type="button" value="Next" '.
1.417 albertel 2090: 'onClick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.126 ng 2091: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.349 albertel 2092: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2093: "' name='increment' />";
1.45 ng 2094: $endform.='</td><tr></table></form>';
1.324 albertel 2095: $endform.=&show_grading_menu_form($symb);
1.41 ng 2096: $request->print($endform);
2097: }
2098: return '';
1.38 ng 2099: }
2100:
1.44 ng 2101: #--- Retrieve the last submission for all the parts
1.38 ng 2102: sub get_last_submission {
1.119 ng 2103: my ($returnhash)=@_;
1.46 ng 2104: my (@string,$timestamp);
1.119 ng 2105: if ($$returnhash{'version'}) {
1.46 ng 2106: my %lasthash=();
2107: my ($version);
1.119 ng 2108: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2109: foreach my $key (sort(split(/\:/,
2110: $$returnhash{$version.':keys'}))) {
2111: $lasthash{$key}=$$returnhash{$version.':'.$key};
2112: $timestamp =
2113: scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2114: }
2115: }
1.397 albertel 2116: foreach my $key (keys(%lasthash)) {
2117: next if ($key !~ /\.submission$/);
2118:
2119: my ($partid,$foo) = split(/submission$/,$key);
2120: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2121: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2122: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2123: }
2124: }
1.397 albertel 2125: if (!@string) {
2126: $string[0] =
1.398 albertel 2127: '<span class="LC_warning">Nothing submitted - no attempts.</span>';
1.397 albertel 2128: }
2129: return (\@string,\$timestamp);
1.38 ng 2130: }
1.35 ng 2131:
1.44 ng 2132: #--- High light keywords, with style choosen by user.
1.38 ng 2133: sub keywords_highlight {
1.44 ng 2134: my $string = shift;
1.257 albertel 2135: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2136: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2137: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2138: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2139: foreach my $keyword (@keylist) {
2140: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2141: }
2142: return $string;
1.38 ng 2143: }
1.36 ng 2144:
1.44 ng 2145: #--- Called from submission routine
1.38 ng 2146: sub processHandGrade {
1.41 ng 2147: my ($request) = shift;
1.324 albertel 2148: my $symb = &get_symb($request);
2149: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2150: my $button = $env{'form.gradeOpt'};
2151: my $ngrade = $env{'form.NCT'};
2152: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2153: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2154: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2155:
1.44 ng 2156: if ($button eq 'Save & Next') {
2157: my $ctr = 0;
2158: while ($ctr < $ngrade) {
1.257 albertel 2159: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2160: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2161: if ($errorflag eq 'no_score') {
2162: $ctr++;
2163: next;
2164: }
1.104 albertel 2165: if ($errorflag eq 'not_allowed') {
1.398 albertel 2166: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2167: $ctr++;
2168: next;
2169: }
1.257 albertel 2170: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2171: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2172: my $restitle = &Apache::lonnet::gettitle($symb);
2173: my ($feedurl,$showsymb) =
2174: &get_feedurl_and_symb($symb,$uname,$udom);
2175: my $messagetail;
1.62 albertel 2176: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2177: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2178: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2179: $subject.=' ['.$restitle.']';
1.44 ng 2180: my (@msgnum) = split(/,/,$includemsg);
2181: foreach (@msgnum) {
1.257 albertel 2182: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2183: }
1.80 ng 2184: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2185: if ($env{'form.withgrades'.$ctr}) {
2186: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2187: $messagetail = " for <a href=\"".
1.418 albertel 2188: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2189: }
2190: $msgstatus =
2191: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2192: $message.$messagetail,
1.418 albertel 2193: undef,$feedurl,undef,
1.386 raeburn 2194: undef,undef,$showsymb,
2195: $restitle);
2196: $request->print('<br />'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
1.296 www 2197: $msgstatus);
1.44 ng 2198: }
1.257 albertel 2199: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2200: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2201: foreach my $collabstr (@collabstrs) {
2202: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2203: foreach my $collaborator (@collaborators) {
1.150 albertel 2204: my ($errorflag,$pts,$wgt) =
1.324 albertel 2205: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2206: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2207: if ($errorflag eq 'not_allowed') {
1.362 albertel 2208: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2209: next;
1.418 albertel 2210: } elsif ($message ne '') {
2211: my ($baseurl,$showsymb) =
2212: &get_feedurl_and_symb($symb,$collaborator,
2213: $udom);
2214: if ($env{'form.withgrades'.$ctr}) {
2215: $messagetail = " for <a href=\"".
1.386 raeburn 2216: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2217: }
1.418 albertel 2218: $msgstatus =
2219: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2220: }
1.44 ng 2221: }
2222: }
2223: }
2224: $ctr++;
2225: }
2226: }
2227:
1.257 albertel 2228: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2229: # Keywords sorted in alphabatical order
1.257 albertel 2230: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2231: my %keyhash = ();
1.257 albertel 2232: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2233: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2234: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2235: $env{'form.keywords'} = join(' ',@keywords);
2236: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2237: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2238: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2239: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2240: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2241:
2242: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2243: # New messages are saved in env for the next student.
1.119 ng 2244: # All messages are saved in nohist_handgrade.db
2245: my ($ctr,$idx) = (1,1);
1.257 albertel 2246: while ($ctr <= $env{'form.savemsgN'}) {
2247: if ($env{'form.savemsg'.$ctr} ne '') {
2248: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2249: $idx++;
2250: }
2251: $ctr++;
1.41 ng 2252: }
1.119 ng 2253: $ctr = 0;
2254: while ($ctr < $ngrade) {
1.257 albertel 2255: if ($env{'form.newmsg'.$ctr} ne '') {
2256: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2257: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2258: $idx++;
2259: }
2260: $ctr++;
1.41 ng 2261: }
1.257 albertel 2262: $env{'form.savemsgN'} = --$idx;
2263: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2264: my $putresult = &Apache::lonnet::put
1.301 albertel 2265: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2266: }
1.44 ng 2267: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2268: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2269: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2270: my ($ctr,$total) = (0,0);
2271: while ($ctr < $ngrade) {
1.257 albertel 2272: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2273: $ctr++;
2274: }
1.257 albertel 2275: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2276: $ctr = 0;
2277: while ($ctr < $total) {
1.257 albertel 2278: my $processUser = $env{'form.unamedom'.$ctr};
2279: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2280: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2281: &submission($request,$ctr,$total-1);
1.41 ng 2282: $ctr++;
2283: }
2284: return '';
2285: }
1.36 ng 2286:
1.121 ng 2287: # Go directly to grade student - from submission or link from chart page
1.120 ng 2288: if ($button eq 'Grade Student') {
1.324 albertel 2289: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2290: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2291: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2292: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2293: &submission($request,0,0);
2294: return '';
2295: }
2296:
1.44 ng 2297: # Get the next/previous one or group of students
1.257 albertel 2298: my $firststu = $env{'form.unamedom0'};
2299: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2300: my $ctr = 2;
1.41 ng 2301: while ($laststu eq '') {
1.257 albertel 2302: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2303: $ctr++;
2304: $laststu = $firststu if ($ctr > $ngrade);
2305: }
1.44 ng 2306:
1.41 ng 2307: my (@parsedlist,@nextlist);
2308: my ($nextflg) = 0;
1.294 albertel 2309: foreach (sort
2310: {
2311: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2312: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2313: }
2314: return $a cmp $b;
2315: } (keys(%$fullname))) {
1.41 ng 2316: if ($nextflg == 1 && $button =~ /Next$/) {
2317: push @parsedlist,$_;
2318: }
2319: $nextflg = 1 if ($_ eq $laststu);
2320: if ($button eq 'Previous') {
2321: last if ($_ eq $firststu);
2322: push @parsedlist,$_;
2323: }
2324: }
2325: $ctr = 0;
2326: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2327: my ($partlist) = &response_type($symb);
1.41 ng 2328: foreach my $student (@parsedlist) {
1.257 albertel 2329: my $submitonly=$env{'form.submitonly'};
1.41 ng 2330: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2331:
2332: if ($submitonly eq 'queued') {
2333: my %queue_status =
2334: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2335: $udom,$uname);
2336: next if (!defined($queue_status{'gradingqueue'}));
2337: }
2338:
1.156 albertel 2339: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2340: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2341: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2342: my $submitted = 0;
1.248 albertel 2343: my $ungraded = 0;
2344: my $incorrect = 0;
1.145 albertel 2345: foreach (keys(%status)) {
2346: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2347: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2348: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2349: my ($foo,$partid,$foo1) = split(/\./,$_);
2350: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2351: $submitted = 0;
2352: }
1.41 ng 2353: }
1.156 albertel 2354: next if (!$submitted && ($submitonly eq 'yes' ||
2355: $submitonly eq 'incorrect' ||
2356: $submitonly eq 'graded'));
1.248 albertel 2357: next if (!$ungraded && ($submitonly eq 'graded'));
2358: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2359: }
2360: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2361: last if ($ctr == $ntstu);
1.41 ng 2362: $ctr++;
2363: }
1.36 ng 2364:
1.41 ng 2365: $ctr = 0;
2366: my $total = scalar(@nextlist)-1;
1.39 ng 2367:
1.41 ng 2368: foreach (sort @nextlist) {
2369: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2370: $env{'form.student'} = $uname;
2371: $env{'form.userdom'} = $udom;
2372: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2373: &submission($request,$ctr,$total);
2374: $ctr++;
2375: }
2376: if ($total < 0) {
1.398 albertel 2377: my $the_end = '<h3><span class="LC_info">LON-CAPA User Message</span></h3><br />'."\n";
1.41 ng 2378: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2379: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.324 albertel 2380: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2381: $request->print($the_end);
2382: }
2383: return '';
1.38 ng 2384: }
1.36 ng 2385:
1.44 ng 2386: #---- Save the score and award for each student, if changed
1.38 ng 2387: sub saveHandGrade {
1.324 albertel 2388: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2389: my @version_parts;
1.104 albertel 2390: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2391: $env{'request.course.id'});
1.104 albertel 2392: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2393: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2394: my @parts_graded;
1.77 ng 2395: my %newrecord = ();
2396: my ($pts,$wgt) = ('','');
1.269 raeburn 2397: my %aggregate = ();
2398: my $aggregateflag = 0;
1.301 albertel 2399: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2400: foreach my $new_part (@parts) {
1.337 banghart 2401: #collaborator ($submi may vary for different parts
1.259 banghart 2402: if ($submitter && $new_part ne $part) { next; }
2403: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2404: if ($dropMenu eq 'excused') {
1.259 banghart 2405: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2406: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2407: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2408: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2409: }
1.364 banghart 2410: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2411: }
1.125 ng 2412: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2413: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2414: foreach my $key (keys (%record)) {
1.259 banghart 2415: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2416: }
1.259 banghart 2417: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2418: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2419: my $totaltries = $record{'resource.'.$part.'.tries'};
2420:
2421: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2422: [$new_part]);
2423: my $aggtries =$totaltries;
1.269 raeburn 2424: if ($last_resets{$new_part}) {
1.270 albertel 2425: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2426: $new_part);
1.269 raeburn 2427: }
1.270 albertel 2428:
2429: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2430: if ($aggtries > 0) {
1.327 albertel 2431: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2432: $aggregateflag = 1;
2433: }
1.125 ng 2434: } elsif ($dropMenu eq '') {
1.259 banghart 2435: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2436: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2437: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2438: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2439: next;
2440: }
1.259 banghart 2441: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2442: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2443: my $partial= $pts/$wgt;
1.259 banghart 2444: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2445: #do not update score for part if not changed.
1.346 banghart 2446: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2447: next;
1.251 banghart 2448: } else {
1.259 banghart 2449: push @parts_graded, $new_part;
1.153 albertel 2450: }
1.259 banghart 2451: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2452: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2453: }
1.259 banghart 2454: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2455: if ($partial == 0) {
1.153 albertel 2456: if ($record{$reckey} ne 'incorrect_by_override') {
2457: $newrecord{$reckey} = 'incorrect_by_override';
2458: }
1.41 ng 2459: } else {
1.153 albertel 2460: if ($record{$reckey} ne 'correct_by_override') {
2461: $newrecord{$reckey} = 'correct_by_override';
2462: }
2463: }
2464: if ($submitter &&
1.259 banghart 2465: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2466: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2467: }
1.259 banghart 2468: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2469: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2470: }
1.259 banghart 2471: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2472: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2473: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2474: $dropMenu eq 'reset status')
2475: {
1.342 banghart 2476: push (@version_parts,$new_part);
1.259 banghart 2477: }
1.41 ng 2478: }
1.301 albertel 2479: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2480: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2481:
1.344 albertel 2482: if (%newrecord) {
2483: if (@version_parts) {
1.364 banghart 2484: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2485: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2486: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2487: foreach my $new_part (@version_parts) {
2488: &handback_files($request,$symb,$stuname,$domain,$newflg,
2489: $new_part,\%newrecord);
2490: }
1.259 banghart 2491: }
1.44 ng 2492: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2493: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2494: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2495: $cdom,$cnum,$domain,$stuname);
1.41 ng 2496: }
1.269 raeburn 2497: if ($aggregateflag) {
2498: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2499: $cdom,$cnum);
1.269 raeburn 2500: }
1.301 albertel 2501: return ('',$pts,$wgt);
1.36 ng 2502: }
1.322 albertel 2503:
1.380 albertel 2504: sub check_and_remove_from_queue {
2505: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2506: my @ungraded_parts;
2507: foreach my $part (@{$parts}) {
2508: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2509: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2510: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2511: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2512: ) {
2513: push(@ungraded_parts, $part);
2514: }
2515: }
2516: if ( !@ungraded_parts ) {
2517: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2518: $cnum,$domain,$stuname);
2519: }
2520: }
2521:
1.337 banghart 2522: sub handback_files {
2523: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.359 www 2524: my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
2525: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2526:
2527: my @part_response_id = &flatten_responseType($responseType);
2528: foreach my $part_response_id (@part_response_id) {
2529: my ($part_id,$resp_id) = @{ $part_response_id };
2530: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2531: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2532: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2533: my $file_counter = 1;
1.367 albertel 2534: my $file_msg;
1.337 banghart 2535: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2536: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2537: my ($directory,$answer_file) =
2538: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2539: my ($answer_name,$answer_ver,$answer_ext) =
2540: &file_name_version_ext($answer_file);
1.355 banghart 2541: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.341 banghart 2542: my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
1.338 banghart 2543: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2544: # fix file name
2545: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2546: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2547: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2548: $save_file_name);
1.337 banghart 2549: if ($result !~ m|^/uploaded/|) {
1.401 albertel 2550: $request->print('<span class="LC_error">An error occurred ('.$result.
1.398 albertel 2551: ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'</span><br />');
1.356 banghart 2552: } else {
1.360 banghart 2553: # mark the file as read only
2554: my @files = ($save_file_name);
1.372 albertel 2555: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2556: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2557: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2558: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2559: }
2560: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2561: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2562:
1.337 banghart 2563: }
2564: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2565: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2566: $file_counter++;
2567: }
1.367 albertel 2568: my $subject = "File Handed Back by Instructor ";
2569: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2570: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2571: $message .= ' The returned file(s) are named: '. $file_msg;
2572: $message .= " and can be found in your portfolio space.";
1.418 albertel 2573: my ($feedurl,$showsymb) =
2574: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2575: my $restitle = &Apache::lonnet::gettitle($symb);
2576: my $msgstatus =
2577: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2578: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2579: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2580: }
2581: }
1.338 banghart 2582: return;
1.337 banghart 2583: }
2584:
1.418 albertel 2585: sub get_feedurl_and_symb {
2586: my ($symb,$uname,$udom) = @_;
2587: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2588: $url = &Apache::lonnet::clutter($url);
2589: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2590: $symb,$udom,$uname);
2591: if ($encrypturl =~ /^yes$/i) {
2592: &Apache::lonenc::encrypted(\$url,1);
2593: &Apache::lonenc::encrypted(\$symb,1);
2594: }
2595: return ($url,$symb);
2596: }
2597:
1.313 banghart 2598: sub get_submitted_files {
2599: my ($udom,$uname,$partid,$respid,$record) = @_;
2600: my @files;
2601: if ($$record{"resource.$partid.$respid.portfiles"}) {
2602: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2603: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2604: push(@files,$file_url.$file);
2605: }
2606: }
2607: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2608: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2609: }
2610: return (\@files);
2611: }
1.322 albertel 2612:
1.269 raeburn 2613: # ----------- Provides number of tries since last reset.
2614: sub get_num_tries {
2615: my ($record,$last_reset,$part) = @_;
2616: my $timestamp = '';
2617: my $num_tries = 0;
2618: if ($$record{'version'}) {
2619: for (my $version=$$record{'version'};$version>=1;$version--) {
2620: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2621: $timestamp = $$record{$version.':timestamp'};
2622: if ($timestamp > $last_reset) {
2623: $num_tries ++;
2624: } else {
2625: last;
2626: }
2627: }
2628: }
2629: }
2630: return $num_tries;
2631: }
2632:
2633: # ----------- Determine decrements required in aggregate totals
2634: sub decrement_aggs {
2635: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2636: my %decrement = (
2637: attempts => 0,
2638: users => 0,
2639: correct => 0
2640: );
2641: $decrement{'attempts'} = $aggtries;
2642: if ($solvedstatus =~ /^correct/) {
2643: $decrement{'correct'} = 1;
2644: }
2645: if ($aggtries == $totaltries) {
2646: $decrement{'users'} = 1;
2647: }
2648: foreach my $type (keys (%decrement)) {
2649: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2650: }
2651: return;
2652: }
2653:
2654: # ----------- Determine timestamps for last reset of aggregate totals for parts
2655: sub get_last_resets {
1.270 albertel 2656: my ($symb,$courseid,$partids) =@_;
2657: my %last_resets;
1.269 raeburn 2658: my $cdom = $env{'course.'.$courseid.'.domain'};
2659: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2660: my @keys;
2661: foreach my $part (@{$partids}) {
2662: push(@keys,"$symb\0$part\0resettime");
2663: }
2664: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2665: $cdom,$cname);
2666: foreach my $part (@{$partids}) {
2667: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2668: }
1.270 albertel 2669: return %last_resets;
1.269 raeburn 2670: }
2671:
1.251 banghart 2672: # ----------- Handles creating versions for portfolio files as answers
2673: sub version_portfiles {
1.343 banghart 2674: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2675: my $version_parts = join('|',@$v_flag);
1.343 banghart 2676: my @returned_keys;
1.255 banghart 2677: my $parts = join('|', @$parts_graded);
1.359 www 2678: my $portfolio_root = &propath($domain,$stu_name).
2679: '/userfiles/portfolio';
1.277 albertel 2680: foreach my $key (keys(%$record)) {
1.259 banghart 2681: my $new_portfiles;
1.263 banghart 2682: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2683: my @versioned_portfiles;
1.367 albertel 2684: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2685: foreach my $file (@portfiles) {
1.306 banghart 2686: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2687: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2688: my ($answer_name,$answer_ver,$answer_ext) =
2689: &file_name_version_ext($answer_file);
1.306 banghart 2690: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.342 banghart 2691: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2692: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2693: if ($new_answer ne 'problem getting file') {
1.342 banghart 2694: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2695: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2696: [$directory.$new_answer],
1.306 banghart 2697: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2698: }
1.252 banghart 2699: }
1.343 banghart 2700: $$record{$key} = join(',',@versioned_portfiles);
2701: push(@returned_keys,$key);
1.251 banghart 2702: }
2703: }
1.343 banghart 2704: return (@returned_keys);
1.305 banghart 2705: }
2706:
1.307 banghart 2707: sub get_next_version {
1.341 banghart 2708: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2709: my $version;
2710: foreach my $row (@$dir_list) {
2711: my ($file) = split(/\&/,$row,2);
2712: my ($file_name,$file_version,$file_ext) =
2713: &file_name_version_ext($file);
2714: if (($file_name eq $answer_name) &&
2715: ($file_ext eq $answer_ext)) {
2716: # gets here if filename and extension match, regardless of version
2717: if ($file_version ne '') {
2718: # a versioned file is found so save it for later
2719: if ($file_version > $version) {
2720: $version = $file_version;
2721: }
2722: }
2723: }
2724: }
2725: $version ++;
2726: return($version);
2727: }
2728:
1.305 banghart 2729: sub version_selected_portfile {
1.306 banghart 2730: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2731: my ($answer_name,$answer_ver,$answer_ext) =
2732: &file_name_version_ext($file_name);
2733: my $new_answer;
2734: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2735: if($env{'form.copy'} eq '-1') {
2736: &Apache::lonnet::logthis('problem getting file '.$file_name);
2737: $new_answer = 'problem getting file';
2738: } else {
2739: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2740: my $copy_result = &Apache::lonnet::finishuserfileupload(
2741: $stu_name,$domain,'copy',
2742: '/portfolio'.$directory.$new_answer);
2743: }
2744: return ($new_answer);
1.251 banghart 2745: }
2746:
1.304 albertel 2747: sub file_name_version_ext {
2748: my ($file)=@_;
2749: my @file_parts = split(/\./, $file);
2750: my ($name,$version,$ext);
2751: if (@file_parts > 1) {
2752: $ext=pop(@file_parts);
2753: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2754: $version=pop(@file_parts);
2755: }
2756: $name=join('.',@file_parts);
2757: } else {
2758: $name=join('.',@file_parts);
2759: }
2760: return($name,$version,$ext);
2761: }
2762:
1.44 ng 2763: #--------------------------------------------------------------------------------------
2764: #
2765: #-------------------------- Next few routines handles grading by section or whole class
2766: #
2767: #--- Javascript to handle grading by section or whole class
1.42 ng 2768: sub viewgrades_js {
2769: my ($request) = shift;
2770:
1.41 ng 2771: $request->print(<<VIEWJAVASCRIPT);
2772: <script type="text/javascript" language="javascript">
1.45 ng 2773: function writePoint(partid,weight,point) {
1.125 ng 2774: var radioButton = document.classgrade["RADVAL_"+partid];
2775: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2776: if (point == "textval") {
1.125 ng 2777: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2778: if (isNaN(point) || parseFloat(point) < 0) {
2779: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2780: var resetbox = false;
2781: for (var i=0; i<radioButton.length; i++) {
2782: if (radioButton[i].checked) {
2783: textbox.value = i;
2784: resetbox = true;
2785: }
2786: }
2787: if (!resetbox) {
2788: textbox.value = "";
2789: }
2790: return;
2791: }
1.109 matthew 2792: if (parseFloat(point) > parseFloat(weight)) {
2793: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2794: ") greater than the weight for the part. Accept?");
2795: if (resp == false) {
2796: textbox.value = "";
2797: return;
2798: }
2799: }
1.42 ng 2800: for (var i=0; i<radioButton.length; i++) {
2801: radioButton[i].checked=false;
1.109 matthew 2802: if (parseFloat(point) == i) {
1.42 ng 2803: radioButton[i].checked=true;
2804: }
2805: }
1.41 ng 2806:
1.42 ng 2807: } else {
1.125 ng 2808: textbox.value = parseFloat(point);
1.42 ng 2809: }
1.41 ng 2810: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2811: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2812: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2813: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2814: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2815: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2816: if (saveval != "correct") {
2817: scorename.value = point;
1.43 ng 2818: if (selname[0].selected != true) {
2819: selname[0].selected = true;
2820: }
1.42 ng 2821: }
2822: }
1.125 ng 2823: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2824: }
2825:
2826: function writeRadText(partid,weight) {
1.125 ng 2827: var selval = document.classgrade["SELVAL_"+partid];
2828: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2829: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2830: var textbox = document.classgrade["TEXTVAL_"+partid];
2831: if (selval[1].selected || selval[2].selected) {
1.42 ng 2832: for (var i=0; i<radioButton.length; i++) {
2833: radioButton[i].checked=false;
2834:
2835: }
2836: textbox.value = "";
2837:
2838: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2839: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2840: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2841: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2842: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2843: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2844: if ((saveval != "correct") || override) {
1.42 ng 2845: scorename.value = "";
1.125 ng 2846: if (selval[1].selected) {
2847: selname[1].selected = true;
2848: } else {
2849: selname[2].selected = true;
2850: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2851: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2852: }
1.42 ng 2853: }
2854: }
1.43 ng 2855: } else {
2856: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2857: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2858: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2859: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2860: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2861: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2862: if ((saveval != "correct") || override) {
1.125 ng 2863: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2864: selname[0].selected = true;
2865: }
2866: }
2867: }
1.42 ng 2868: }
2869:
2870: function changeSelect(partid,user) {
1.125 ng 2871: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2872: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2873: var point = textbox.value;
1.125 ng 2874: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2875:
1.109 matthew 2876: if (isNaN(point) || parseFloat(point) < 0) {
2877: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2878: textbox.value = "";
2879: return;
2880: }
1.109 matthew 2881: if (parseFloat(point) > parseFloat(weight)) {
2882: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2883: ") greater than the weight of the part. Accept?");
2884: if (resp == false) {
2885: textbox.value = "";
2886: return;
2887: }
2888: }
1.42 ng 2889: selval[0].selected = true;
2890: }
2891:
2892: function changeOneScore(partid,user) {
1.125 ng 2893: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2894: if (selval[1].selected || selval[2].selected) {
2895: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2896: if (selval[2].selected) {
2897: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2898: }
1.269 raeburn 2899: }
1.42 ng 2900: }
2901:
2902: function resetEntry(numpart) {
2903: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2904: var partid = document.classgrade["partid_"+ctpart].value;
2905: var radioButton = document.classgrade["RADVAL_"+partid];
2906: var textbox = document.classgrade["TEXTVAL_"+partid];
2907: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2908: for (var i=0; i<radioButton.length; i++) {
2909: radioButton[i].checked=false;
2910:
2911: }
2912: textbox.value = "";
2913: selval[0].selected = true;
2914:
2915: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2916: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2917: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2918: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2919: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2920: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2921: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2922: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2923: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2924: if (saveselval == "excused") {
1.43 ng 2925: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2926: } else {
1.43 ng 2927: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2928: }
2929: }
1.41 ng 2930: }
1.42 ng 2931: }
2932:
1.41 ng 2933: </script>
2934: VIEWJAVASCRIPT
1.42 ng 2935: }
2936:
1.44 ng 2937: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2938: sub viewgrades {
2939: my ($request) = shift;
2940: &viewgrades_js($request);
1.41 ng 2941:
1.324 albertel 2942: my ($symb) = &get_symb($request);
1.168 albertel 2943: #need to make sure we have the correct data for later EXT calls,
2944: #thus invalidate the cache
2945: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2946: $env{'course.'.$env{'request.course.id'}.'.num'},
2947: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2948: &Apache::lonnet::clear_EXT_cache_status();
2949:
1.398 albertel 2950: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
2951: $result.='<h4><b>Current Resource: </b>'.$env{'form.probTitle'}.'</h4>'."\n";
1.41 ng 2952:
2953: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 2954: $result.=&jscriptNform($symb);
1.41 ng 2955:
1.44 ng 2956: #beginning of class grading form
1.41 ng 2957: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 2958: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 2959: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2960: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2961: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2962: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2963: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2964:
1.126 ng 2965: my $sectionClass;
1.257 albertel 2966: if ($env{'form.section'} eq 'all') {
1.126 ng 2967: $sectionClass='Class </h3>';
1.257 albertel 2968: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2969: $sectionClass='Students in no Section </h3>';
1.52 albertel 2970: } else {
1.257 albertel 2971: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2972: }
1.126 ng 2973: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2974: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2975: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2976: #radio buttons/text box for assigning points for a section or class.
2977: #handles different parts of a problem
1.375 albertel 2978: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 2979: my %weight = ();
2980: my $ctsparts = 0;
1.41 ng 2981: $result.='<table border="0">';
1.45 ng 2982: my %seen = ();
1.375 albertel 2983: my @part_response_id = &flatten_responseType($responseType);
2984: foreach my $part_response_id (@part_response_id) {
2985: my ($partid,$respid) = @{ $part_response_id };
2986: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 2987: next if $seen{$partid};
2988: $seen{$partid}++;
1.375 albertel 2989: my $handgrade=$$handgrade{$part_resp};
1.42 ng 2990: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2991: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2992:
1.44 ng 2993: $result.='<input type="hidden" name="partid_'.
2994: $ctsparts.'" value="'.$partid.'" />'."\n";
2995: $result.='<input type="hidden" name="weight_'.
2996: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.324 albertel 2997: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 2998: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 2999: $result.='<table border="0"><tr>';
1.41 ng 3000: my $ctr = 0;
1.42 ng 3001: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 3002: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3003: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3004: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3005: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3006: $ctr++;
3007: }
3008: $result.='</tr></table>';
1.44 ng 3009: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 3010: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3011: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 3012: $weight{$partid}.' (problem weight)</td>'."\n";
3013: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3014: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3015: $weight{$partid}.')"> '.
1.401 albertel 3016: '<option selected="selected"> </option>'.
1.125 ng 3017: '<option>excused</option>'.
1.265 www 3018: '<option>reset status</option></select></td>'.
1.266 albertel 3019: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 3020: $ctsparts++;
1.41 ng 3021: }
1.52 albertel 3022: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
3023: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.391 banghart 3024: $result.='<input type="button" value="Revert to Default" '.
1.417 albertel 3025: 'onClick="javascript:resetEntry('.$ctsparts.');" target="_self" />';
1.41 ng 3026:
1.44 ng 3027: #table listing all the students in a section/class
3028: #header of table
1.126 ng 3029: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 3030: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 3031: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 3032: '<td>'.&nameUserString('header')."</td>\n";
1.324 albertel 3033: my (@parts) = sort(&getpartlist($symb));
3034: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3035: my @partids = ();
1.41 ng 3036: foreach my $part (@parts) {
3037: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 3038: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 3039: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3040: my ($partid) = &split_part_type($part);
1.269 raeburn 3041: push(@partids, $partid);
1.324 albertel 3042: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3043: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 3044: $result.='<td><b>Score Part:</b> '.$display_part.
3045: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 3046: next;
1.207 albertel 3047: } else {
3048: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 3049: }
1.53 albertel 3050: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 3051: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 3052: }
3053: $result.='</tr>';
1.44 ng 3054:
1.270 albertel 3055: my %last_resets =
3056: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3057:
1.41 ng 3058: #get info for each student
1.44 ng 3059: #list all the students - with points and grade status
1.257 albertel 3060: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3061: my $ctr = 0;
1.294 albertel 3062: foreach (sort
3063: {
3064: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3065: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3066: }
3067: return $a cmp $b;
3068: } (keys(%$fullname))) {
1.126 ng 3069: $ctr++;
1.324 albertel 3070: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3071: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3072: }
3073: $result.='</table></td></tr></table>';
3074: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 3075: $result.='<input type="button" value="Save" '.
1.417 albertel 3076: 'onClick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3077: if (scalar(%$fullname) eq 0) {
3078: my $colspan=3+scalar(@parts);
1.398 albertel 3079: $result='<span class="LC_warning">There are no students in section "'.$env{'form.section'}.
3080: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</span>';
1.96 albertel 3081: }
1.324 albertel 3082: $result.=&show_grading_menu_form($symb);
1.41 ng 3083: return $result;
3084: }
3085:
1.44 ng 3086: #--- call by previous routine to display each student
1.41 ng 3087: sub viewstudentgrade {
1.324 albertel 3088: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3089: my ($uname,$udom) = split(/:/,$student);
3090: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3091: my %aggregates = ();
1.233 albertel 3092: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
3093: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3094: "\n".$ctr.' </td><td> '.
1.44 ng 3095: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3096: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3097: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3098: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3099: foreach my $apart (@$parts) {
3100: my ($part,$type) = &split_part_type($apart);
1.41 ng 3101: my $score=$record{"resource.$part.$type"};
1.276 albertel 3102: $result.='<td align="center">';
1.269 raeburn 3103: my ($aggtries,$totaltries);
3104: unless (exists($aggregates{$part})) {
1.270 albertel 3105: $totaltries = $record{'resource.'.$part.'.tries'};
3106:
3107: $aggtries = $totaltries;
1.269 raeburn 3108: if ($$last_resets{$part}) {
1.270 albertel 3109: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3110: $part);
3111: }
1.269 raeburn 3112: $result.='<input type="hidden" name="'.
3113: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3114: $result.='<input type="hidden" name="'.
3115: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3116: $aggregates{$part} = 1;
3117: }
1.41 ng 3118: if ($type eq 'awarded') {
1.320 albertel 3119: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3120: $result.='<input type="hidden" name="'.
1.89 albertel 3121: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3122: $result.='<input type="text" name="'.
1.89 albertel 3123: 'GD_'.$student.'_'.$part.'_awarded" '.
3124: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3125: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3126: } elsif ($type eq 'solved') {
3127: my ($status,$foo)=split(/_/,$score,2);
3128: $status = 'nothing' if ($status eq '');
1.89 albertel 3129: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3130: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3131: $result.=' <select name="'.
1.89 albertel 3132: 'GD_'.$student.'_'.$part.'_solved" '.
3133: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.401 albertel 3134: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected">excused</option>'
3135: : '<option selected="selected"> </option><option>excused</option>')."\n";
1.125 ng 3136: $result.='<option>reset status</option>';
1.126 ng 3137: $result.="</select> </td>\n";
1.122 ng 3138: } else {
3139: $result.='<input type="hidden" name="'.
3140: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3141: "\n";
1.233 albertel 3142: $result.='<input type="text" name="'.
1.122 ng 3143: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3144: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3145: }
3146: }
3147: $result.='</tr>';
3148: return $result;
1.38 ng 3149: }
3150:
1.44 ng 3151: #--- change scores for all the students in a section/class
3152: # record does not get update if unchanged
1.38 ng 3153: sub editgrades {
1.41 ng 3154: my ($request) = @_;
3155:
1.324 albertel 3156: my $symb=&get_symb($request);
1.398 albertel 3157: my $title='<h3><span class="LC_info">Current Grade Status</span></h3>';
3158: $title.='<h4><b>Current Resource: </b>'.$env{'form.probTitle'}.'</h4><br />'."\n";
3159: $title.='<h4><b>Section: </b>'.$env{'form.section'}.'</h4>'."\n";
1.126 ng 3160:
1.44 ng 3161: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 3162: $result.= '<table border="0"><tr bgcolor="#deffff">'.
3163: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
3164: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 3165:
3166: my %scoreptr = (
3167: 'correct' =>'correct_by_override',
3168: 'incorrect'=>'incorrect_by_override',
3169: 'excused' =>'excused',
3170: 'ungraded' =>'ungraded_attempted',
3171: 'nothing' => '',
3172: );
1.257 albertel 3173: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3174:
1.44 ng 3175: my (@partid);
3176: my %weight = ();
1.54 albertel 3177: my %columns = ();
1.44 ng 3178: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3179:
1.324 albertel 3180: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3181: my $header;
1.257 albertel 3182: while ($ctr < $env{'form.totalparts'}) {
3183: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 3184: push @partid,$partid;
1.257 albertel 3185: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3186: $ctr++;
1.54 albertel 3187: }
1.324 albertel 3188: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3189: foreach my $partid (@partid) {
3190: $header .= '<td align="center"> <b>Old Score</b> </td>'.
3191: '<td align="center"> <b>New Score</b> </td>';
3192: $columns{$partid}=2;
3193: foreach my $stores (@parts) {
3194: my ($part,$type) = &split_part_type($stores);
3195: if ($part !~ m/^\Q$partid\E/) { next;}
3196: if ($type eq 'awarded' || $type eq 'solved') { next; }
3197: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3198: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 3199: $display =~ s/Number of Attempts/Tries/;
3200: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
3201: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 3202: $columns{$partid}+=2;
3203: }
3204: }
3205: foreach my $partid (@partid) {
1.324 albertel 3206: my $display_part=&get_display_part($partid,$symb);
1.54 albertel 3207: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 3208: '" align="center"><b>Part:</b> '.$display_part.
3209: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 3210:
1.44 ng 3211: }
3212: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 3213: $result .= $header;
1.44 ng 3214: $result .= '</tr>'."\n";
1.93 albertel 3215: my $noupdate;
1.126 ng 3216: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3217: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3218: my $line;
1.257 albertel 3219: my $user = $env{'form.ctr'.$i};
1.281 albertel 3220: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3221: my %newrecord;
3222: my $updateflag = 0;
1.281 albertel 3223: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3224: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3225: if (!&canmodify($usec)) {
1.126 ng 3226: my $numcols=scalar(@partid)*4+2;
1.399 albertel 3227: $noupdate.=$line."<td colspan=\"$numcols\"><span class=\"LC_warning\">Not allowed to modify student</span></td></tr>";
1.105 albertel 3228: next;
3229: }
1.269 raeburn 3230: my %aggregate = ();
3231: my $aggregateflag = 0;
1.281 albertel 3232: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3233: foreach (@partid) {
1.257 albertel 3234: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3235: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3236: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3237: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3238: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3239: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3240: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3241: my $score;
3242: if ($partial eq '') {
1.257 albertel 3243: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3244: } elsif ($partial > 0) {
3245: $score = 'correct_by_override';
3246: } elsif ($partial == 0) {
3247: $score = 'incorrect_by_override';
3248: }
1.257 albertel 3249: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3250: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3251:
1.292 albertel 3252: $newrecord{'resource.'.$_.'.regrader'}=
3253: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3254: if ($dropMenu eq 'reset status' &&
3255: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3256: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3257: $newrecord{'resource.'.$_.'.solved'} = '';
3258: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3259: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3260: $updateflag = 1;
1.269 raeburn 3261: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3262: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3263: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3264: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3265: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3266: $aggregateflag = 1;
3267: }
1.139 albertel 3268: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3269: $updateflag = 1;
3270: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3271: $newrecord{'resource.'.$_.'.solved'} = $score;
3272: $rec_update++;
1.125 ng 3273: }
3274:
1.93 albertel 3275: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3276: '<td align="center">'.$awarded.
3277: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3278:
1.54 albertel 3279:
3280: my $partid=$_;
3281: foreach my $stores (@parts) {
3282: my ($part,$type) = &split_part_type($stores);
3283: if ($part !~ m/^\Q$partid\E/) { next;}
3284: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3285: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3286: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3287: if ($awarded ne '' && $awarded ne $old_aw) {
3288: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3289: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3290: $updateflag=1;
3291: }
1.93 albertel 3292: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3293: '<td align="center">'.$awarded.' </td>';
3294: }
1.44 ng 3295: }
1.93 albertel 3296: $line.='</tr>'."\n";
1.301 albertel 3297:
3298: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3299: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3300:
1.44 ng 3301: if ($updateflag) {
3302: $count++;
1.257 albertel 3303: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3304: $udom,$uname);
1.301 albertel 3305:
3306: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3307: $cnum,$udom,$uname)) {
3308: # need to figure out if should be in queue.
3309: my %record =
3310: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3311: $udom,$uname);
3312: my $all_graded = 1;
3313: my $none_graded = 1;
3314: foreach my $part (@parts) {
3315: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3316: $all_graded = 0;
3317: } else {
3318: $none_graded = 0;
3319: }
3320: }
3321:
3322: if ($all_graded || $none_graded) {
3323: &Apache::bridgetask::remove_from_queue('gradingqueue',
3324: $symb,$cdom,$cnum,
3325: $udom,$uname);
3326: }
3327: }
3328:
1.126 ng 3329: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3330: $updateCtr++;
1.93 albertel 3331: } else {
1.126 ng 3332: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3333: $noupdateCtr++;
1.44 ng 3334: }
1.269 raeburn 3335: if ($aggregateflag) {
3336: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3337: $cdom,$cnum);
1.269 raeburn 3338: }
1.93 albertel 3339: }
3340: if ($noupdate) {
1.126 ng 3341: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3342: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3343: $result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr><tr bgcolor="#ffffde">'.$noupdate;
1.44 ng 3344: }
1.72 ng 3345: $result .= '</table></td></tr></table>'."\n".
1.324 albertel 3346: &show_grading_menu_form ($symb);
1.125 ng 3347: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3348: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3349: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3350: return $title.$msg.$result;
1.5 albertel 3351: }
1.54 albertel 3352:
3353: sub split_part_type {
3354: my ($partstr) = @_;
3355: my ($temp,@allparts)=split(/_/,$partstr);
3356: my $type=pop(@allparts);
3357: my $part=join('.',@allparts);
3358: return ($part,$type);
3359: }
3360:
1.44 ng 3361: #------------- end of section for handling grading by section/class ---------
3362: #
3363: #----------------------------------------------------------------------------
3364:
1.5 albertel 3365:
1.44 ng 3366: #----------------------------------------------------------------------------
3367: #
3368: #-------------------------- Next few routines handles grading by csv upload
3369: #
3370: #--- Javascript to handle csv upload
1.27 albertel 3371: sub csvupload_javascript_reverse_associate {
1.246 albertel 3372: my $error1=&mt('You need to specify the username or ID');
3373: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3374: return(<<ENDPICK);
3375: function verify(vf) {
3376: var foundsomething=0;
3377: var founduname=0;
1.243 albertel 3378: var foundID=0;
1.27 albertel 3379: for (i=0;i<=vf.nfields.value;i++) {
3380: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3381: if (i==0 && tw!=0) { foundID=1; }
3382: if (i==1 && tw!=0) { founduname=1; }
3383: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3384: }
1.246 albertel 3385: if (founduname==0 && foundID==0) {
3386: alert('$error1');
3387: return;
1.27 albertel 3388: }
3389: if (foundsomething==0) {
1.246 albertel 3390: alert('$error2');
3391: return;
1.27 albertel 3392: }
3393: vf.submit();
3394: }
3395: function flip(vf,tf) {
3396: var nw=eval('vf.f'+tf+'.selectedIndex');
3397: var i;
3398: for (i=0;i<=vf.nfields.value;i++) {
3399: //can not pick the same destination field for both name and domain
3400: if (((i ==0)||(i ==1)) &&
3401: ((tf==0)||(tf==1)) &&
3402: (i!=tf) &&
3403: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3404: eval('vf.f'+i+'.selectedIndex=0;')
3405: }
3406: }
3407: }
3408: ENDPICK
3409: }
3410:
3411: sub csvupload_javascript_forward_associate {
1.246 albertel 3412: my $error1=&mt('You need to specify the username or ID');
3413: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3414: return(<<ENDPICK);
3415: function verify(vf) {
3416: var foundsomething=0;
3417: var founduname=0;
1.243 albertel 3418: var foundID=0;
1.27 albertel 3419: for (i=0;i<=vf.nfields.value;i++) {
3420: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3421: if (tw==1) { foundID=1; }
3422: if (tw==2) { founduname=1; }
3423: if (tw>3) { foundsomething=1; }
1.27 albertel 3424: }
1.246 albertel 3425: if (founduname==0 && foundID==0) {
3426: alert('$error1');
3427: return;
1.27 albertel 3428: }
3429: if (foundsomething==0) {
1.246 albertel 3430: alert('$error2');
3431: return;
1.27 albertel 3432: }
3433: vf.submit();
3434: }
3435: function flip(vf,tf) {
3436: var nw=eval('vf.f'+tf+'.selectedIndex');
3437: var i;
3438: //can not pick the same destination field twice
3439: for (i=0;i<=vf.nfields.value;i++) {
3440: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3441: eval('vf.f'+i+'.selectedIndex=0;')
3442: }
3443: }
3444: }
3445: ENDPICK
3446: }
3447:
1.26 albertel 3448: sub csvuploadmap_header {
1.324 albertel 3449: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3450: my $javascript;
1.257 albertel 3451: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3452: $javascript=&csvupload_javascript_reverse_associate();
3453: } else {
3454: $javascript=&csvupload_javascript_forward_associate();
3455: }
1.45 ng 3456:
1.324 albertel 3457: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3458: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3459: my $ignore=&mt('Ignore First Line');
1.418 albertel 3460: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3461: $request->print(<<ENDPICK);
1.26 albertel 3462: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3463: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3464: $result
1.326 albertel 3465: <hr />
1.26 albertel 3466: <h3>Identify fields</h3>
3467: Total number of records found in file: $distotal <hr />
3468: Enter as many fields as you can. The system will inform you and bring you back
3469: to this page if the data selected is insufficient to run your class.<hr />
3470: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3471: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3472: <input type="hidden" name="associate" value="" />
3473: <input type="hidden" name="phase" value="three" />
3474: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3475: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3476: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3477: <input type="hidden" name="upfile_associate"
1.257 albertel 3478: value="$env{'form.upfile_associate'}" />
1.26 albertel 3479: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3480: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3481: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3482: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3483: <hr />
3484: <script type="text/javascript" language="Javascript">
3485: $javascript
3486: </script>
3487: ENDPICK
1.118 ng 3488: return '';
1.26 albertel 3489:
3490: }
3491:
3492: sub csvupload_fields {
1.324 albertel 3493: my ($symb) = @_;
3494: my (@parts) = &getpartlist($symb);
1.243 albertel 3495: my @fields=(['ID','Student ID'],
3496: ['username','Student Username'],
3497: ['domain','Student Domain']);
1.324 albertel 3498: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3499: foreach my $part (sort(@parts)) {
3500: my @datum;
3501: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3502: my $name=$part;
3503: if (!$display) { $display = $name; }
3504: @datum=($name,$display);
1.244 albertel 3505: if ($name=~/^stores_(.*)_awarded/) {
3506: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3507: }
1.41 ng 3508: push(@fields,\@datum);
3509: }
3510: return (@fields);
1.26 albertel 3511: }
3512:
3513: sub csvuploadmap_footer {
1.41 ng 3514: my ($request,$i,$keyfields) =@_;
3515: $request->print(<<ENDPICK);
1.26 albertel 3516: </table>
3517: <input type="hidden" name="nfields" value="$i" />
3518: <input type="hidden" name="keyfields" value="$keyfields" />
3519: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3520: </form>
3521: ENDPICK
3522: }
3523:
1.283 albertel 3524: sub checkforfile_js {
1.86 ng 3525: my $result =<<CSVFORMJS;
3526: <script type="text/javascript" language="javascript">
3527: function checkUpload(formname) {
3528: if (formname.upfile.value == "") {
3529: alert("Please use the browse button to select a file from your local directory.");
3530: return false;
3531: }
3532: formname.submit();
3533: }
3534: </script>
3535: CSVFORMJS
1.283 albertel 3536: return $result;
3537: }
3538:
3539: sub upcsvScores_form {
3540: my ($request) = shift;
1.324 albertel 3541: my ($symb)=&get_symb($request);
1.283 albertel 3542: if (!$symb) {return '';}
3543: my $result=&checkforfile_js();
1.257 albertel 3544: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3545: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3546: $result.=$table;
1.326 albertel 3547: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3548: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.370 www 3549: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource').
1.86 ng 3550: '.</b></td></tr>'."\n";
3551: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3552: my $upload=&mt("Upload Scores");
1.86 ng 3553: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3554: my $ignore=&mt('Ignore First Line');
1.418 albertel 3555: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3556: $result.=<<ENDUPFORM;
1.106 albertel 3557: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3558: <input type="hidden" name="symb" value="$symb" />
3559: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3560: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3561: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3562: $upfile_select
1.370 www 3563: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3564: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3565: </form>
3566: ENDUPFORM
1.370 www 3567: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3568: &mt("How do I create a CSV file from a spreadsheet"))
3569: .'</td></tr></table>'."\n";
1.86 ng 3570: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3571: $result.=&show_grading_menu_form($symb);
1.86 ng 3572: return $result;
3573: }
3574:
3575:
1.26 albertel 3576: sub csvuploadmap {
1.41 ng 3577: my ($request)= @_;
1.324 albertel 3578: my ($symb)=&get_symb($request);
1.41 ng 3579: if (!$symb) {return '';}
1.72 ng 3580:
1.41 ng 3581: my $datatoken;
1.257 albertel 3582: if (!$env{'form.datatoken'}) {
1.41 ng 3583: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3584: } else {
1.257 albertel 3585: $datatoken=$env{'form.datatoken'};
1.41 ng 3586: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3587: }
1.41 ng 3588: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3589: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3590: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3591: my ($i,$keyfields);
3592: if (@records) {
1.324 albertel 3593: my @fields=&csvupload_fields($symb);
1.45 ng 3594:
1.257 albertel 3595: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3596: &Apache::loncommon::csv_print_samples($request,\@records);
3597: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3598: \@fields);
3599: foreach (@fields) { $keyfields.=$_->[0].','; }
3600: chop($keyfields);
3601: } else {
3602: unshift(@fields,['none','']);
3603: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3604: \@fields);
1.311 banghart 3605: foreach my $rec (@records) {
3606: my %temp = &Apache::loncommon::record_sep($rec);
3607: if (%temp) {
3608: $keyfields=join(',',sort(keys(%temp)));
3609: last;
3610: }
3611: }
1.41 ng 3612: }
3613: }
3614: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3615: $request->print(&show_grading_menu_form($symb));
1.72 ng 3616:
1.41 ng 3617: return '';
1.27 albertel 3618: }
3619:
1.246 albertel 3620: sub csvuploadoptions {
1.41 ng 3621: my ($request)= @_;
1.324 albertel 3622: my ($symb)=&get_symb($request);
1.257 albertel 3623: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3624: my $ignore=&mt('Ignore First Line');
3625: $request->print(<<ENDPICK);
3626: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3627: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3628: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3629: <!--
1.246 albertel 3630: <p>
3631: <label>
3632: <input type="checkbox" name="show_full_results" />
3633: Show a table of all changes
3634: </label>
3635: </p>
1.302 albertel 3636: -->
1.246 albertel 3637: <p>
3638: <label>
3639: <input type="checkbox" name="overwite_scores" checked="checked" />
3640: Overwrite any existing score
3641: </label>
3642: </p>
3643: ENDPICK
3644: my %fields=&get_fields();
3645: if (!defined($fields{'domain'})) {
1.257 albertel 3646: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3647: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3648: }
1.257 albertel 3649: foreach my $key (sort(keys(%env))) {
1.246 albertel 3650: if ($key !~ /^form\.(.*)$/) { next; }
3651: my $cleankey=$1;
3652: if ($cleankey eq 'command') { next; }
3653: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3654: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3655: }
3656: # FIXME do a check for any duplicated user ids...
3657: # FIXME do a check for any invalid user ids?...
1.290 albertel 3658: $request->print('<input type="submit" value="Assign Grades" /><br />
3659: <hr /></form>'."\n");
1.324 albertel 3660: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3661: return '';
3662: }
3663:
3664: sub get_fields {
3665: my %fields;
1.257 albertel 3666: my @keyfields = split(/\,/,$env{'form.keyfields'});
3667: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3668: if ($env{'form.upfile_associate'} eq 'reverse') {
3669: if ($env{'form.f'.$i} ne 'none') {
3670: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3671: }
3672: } else {
1.257 albertel 3673: if ($env{'form.f'.$i} ne 'none') {
3674: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3675: }
3676: }
1.27 albertel 3677: }
1.246 albertel 3678: return %fields;
3679: }
3680:
3681: sub csvuploadassign {
3682: my ($request)= @_;
1.324 albertel 3683: my ($symb)=&get_symb($request);
1.246 albertel 3684: if (!$symb) {return '';}
1.345 bowersj2 3685: my $error_msg = '';
1.246 albertel 3686: &Apache::loncommon::load_tmp_file($request);
3687: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3688: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3689: my %fields=&get_fields();
1.41 ng 3690: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3691: my $courseid=$env{'request.course.id'};
1.97 albertel 3692: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3693: my @notallowed;
1.41 ng 3694: my @skipped;
3695: my $countdone=0;
3696: foreach my $grade (@gradedata) {
3697: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3698: my $domain;
3699: if ($entries{$fields{'domain'}}) {
3700: $domain=$entries{$fields{'domain'}};
3701: } else {
1.257 albertel 3702: $domain=$env{'form.default_domain'};
1.246 albertel 3703: }
1.243 albertel 3704: $domain=~s/\s//g;
1.41 ng 3705: my $username=$entries{$fields{'username'}};
1.160 albertel 3706: $username=~s/\s//g;
1.243 albertel 3707: if (!$username) {
3708: my $id=$entries{$fields{'ID'}};
1.247 albertel 3709: $id=~s/\s//g;
1.243 albertel 3710: my %ids=&Apache::lonnet::idget($domain,$id);
3711: $username=$ids{$id};
3712: }
1.41 ng 3713: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3714: my $id=$entries{$fields{'ID'}};
3715: $id=~s/\s//g;
3716: if ($id) {
3717: push(@skipped,"$id:$domain");
3718: } else {
3719: push(@skipped,"$username:$domain");
3720: }
1.41 ng 3721: next;
3722: }
1.108 albertel 3723: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3724: if (!&canmodify($usec)) {
3725: push(@notallowed,"$username:$domain");
3726: next;
3727: }
1.244 albertel 3728: my %points;
1.41 ng 3729: my %grades;
3730: foreach my $dest (keys(%fields)) {
1.244 albertel 3731: if ($dest eq 'ID' || $dest eq 'username' ||
3732: $dest eq 'domain') { next; }
3733: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3734: if ($dest=~/stores_(.*)_points/) {
3735: my $part=$1;
3736: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3737: $symb,$domain,$username);
1.345 bowersj2 3738: if ($wgt) {
3739: $entries{$fields{$dest}}=~s/\s//g;
3740: my $pcr=$entries{$fields{$dest}} / $wgt;
3741: my $award='correct_by_override';
3742: $grades{"resource.$part.awarded"}=$pcr;
3743: $grades{"resource.$part.solved"}=$award;
3744: $points{$part}=1;
3745: } else {
3746: $error_msg = "<br />" .
3747: &mt("Some point values were assigned"
3748: ." for problems with a weight "
3749: ."of zero. These values were "
3750: ."ignored.");
3751: }
1.244 albertel 3752: } else {
3753: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3754: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3755: my $store_key=$dest;
3756: $store_key=~s/^stores/resource/;
3757: $store_key=~s/_/\./g;
3758: $grades{$store_key}=$entries{$fields{$dest}};
3759: }
1.41 ng 3760: }
1.398 albertel 3761: if (! %grades) { push(@skipped,"$username:$domain no data to save"); }
1.257 albertel 3762: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3763: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3764: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3765: $env{'request.course.id'},
3766: $domain,$username);
3767: if ($result eq 'ok') {
3768: $request->print('.');
3769: } else {
3770: $request->print("<p>
1.398 albertel 3771: <span class=\"LC_error\">
3772: Failed to save student $username:$domain.
3773: Message when trying to save was ($result)
3774: </span>
1.302 albertel 3775: </p>" );
3776: }
1.41 ng 3777: $request->rflush();
3778: $countdone++;
3779: }
1.398 albertel 3780: $request->print("<br />Saved $countdone students\n");
1.41 ng 3781: if (@skipped) {
1.398 albertel 3782: $request->print('<p><h4><b>Skipped Students</b></h4></p>');
1.106 albertel 3783: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3784: }
3785: if (@notallowed) {
1.398 albertel 3786: $request->print('<p><span class="LC_error">Students Not Allowed to Modify</span></p>');
1.106 albertel 3787: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3788: }
1.106 albertel 3789: $request->print("<br />\n");
1.324 albertel 3790: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 3791: return $error_msg;
1.26 albertel 3792: }
1.44 ng 3793: #------------- end of section for handling csv file upload ---------
3794: #
3795: #-------------------------------------------------------------------
3796: #
1.122 ng 3797: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3798: #
3799: #--- Select a page/sequence and a student to grade
1.68 ng 3800: sub pickStudentPage {
3801: my ($request) = shift;
3802:
3803: $request->print(<<LISTJAVASCRIPT);
3804: <script type="text/javascript" language="javascript">
3805:
3806: function checkPickOne(formname) {
1.76 ng 3807: if (radioSelection(formname.student) == null) {
1.68 ng 3808: alert("Please select the student you wish to grade.");
3809: return;
3810: }
1.125 ng 3811: ptr = pullDownSelection(formname.selectpage);
3812: formname.page.value = formname["page"+ptr].value;
3813: formname.title.value = formname["title"+ptr].value;
1.68 ng 3814: formname.submit();
3815: }
3816:
3817: </script>
3818: LISTJAVASCRIPT
1.118 ng 3819: &commonJSfunctions($request);
1.324 albertel 3820: my ($symb) = &get_symb($request);
1.257 albertel 3821: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3822: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3823: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3824:
1.398 albertel 3825: my $result='<h3><span class="LC_info"> '.
3826: 'Manual Grading by Page or Sequence</span></h3>';
1.68 ng 3827:
1.80 ng 3828: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3829: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.423 albertel 3830: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 3831: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3832: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3833: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3834: my $ctr=0;
1.68 ng 3835: foreach (@$titles) {
3836: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3837: $result.='<option value="'.$ctr.'" '.
1.401 albertel 3838: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 3839: '>'.$showtitle.'</option>'."\n";
1.70 ng 3840: $ctr++;
1.68 ng 3841: }
1.326 albertel 3842: $result.= '</select>'."<br />\n";
1.70 ng 3843: $ctr=0;
3844: foreach (@$titles) {
3845: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3846: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3847: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3848: $ctr++;
3849: }
1.72 ng 3850: $result.='<input type="hidden" name="page" />'."\n".
3851: '<input type="hidden" name="title" />'."\n";
1.68 ng 3852:
1.401 albertel 3853: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="checked" /> no </label>'."\n".
1.288 albertel 3854: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3855:
1.71 ng 3856: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3857: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
1.401 albertel 3858: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> by dates and submissions</label>'."\n".
1.288 albertel 3859: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3860:
1.68 ng 3861: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3862: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3863: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 3864: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 3865: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3866:
1.382 albertel 3867: $result.=' <b>'.&mt('Use CODE:').' </b>'.
3868: '<input type="text" name="CODE" value="" /><br />'."\n";
3869:
1.80 ng 3870: $result.=' <input type="button" '.
1.126 ng 3871: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3872:
1.68 ng 3873: $request->print($result);
3874:
1.326 albertel 3875: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br />'.
1.68 ng 3876: '<table border="0"><tr><td bgcolor="#777777">'.
3877: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3878: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3879: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3880: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3881: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3882:
1.76 ng 3883: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3884: my $ptr = 1;
1.294 albertel 3885: foreach my $student (sort
3886: {
3887: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3888: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3889: }
3890: return $a cmp $b;
3891: } (keys(%$fullname))) {
1.68 ng 3892: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3893: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3894: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3895: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3896: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3897: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3898: $ptr++;
3899: }
1.381 albertel 3900: $studentTable.='</td><td> </td><td> </td></tr>' if ($ptr%2 == 0);
3901: $studentTable.='</table></td></tr></table>'."\n";
1.126 ng 3902: $studentTable.='<input type="button" '.
3903: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3904:
1.324 albertel 3905: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 3906: $request->print($studentTable);
3907:
3908: return '';
3909: }
3910:
3911: sub getSymbMap {
1.132 bowersj2 3912: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3913:
3914: my %symbx = ();
3915: my @titles = ();
1.117 bowersj2 3916: my $minder = 0;
3917:
3918: # Gather every sequence that has problems.
1.240 albertel 3919: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3920: 1,0,1);
1.117 bowersj2 3921: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3922: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 3923: my $title = $minder.'.'.
3924: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
3925: push(@titles, $title); # minder in case two titles are identical
3926: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 3927: $minder++;
1.241 albertel 3928: }
1.68 ng 3929: }
3930: return \@titles,\%symbx;
3931: }
3932:
1.72 ng 3933: #
3934: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3935: sub displayPage {
3936: my ($request) = shift;
3937:
1.324 albertel 3938: my ($symb) = &get_symb($request);
1.257 albertel 3939: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3940: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3941: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3942: my $pageTitle = $env{'form.page'};
1.103 albertel 3943: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3944: my ($uname,$udom) = split(/:/,$env{'form.student'});
3945: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3946:
3947: #need to make sure we have the correct data for later EXT calls,
3948: #thus invalidate the cache
3949: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3950: $env{'course.'.$env{'request.course.id'}.'.num'},
3951: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3952: &Apache::lonnet::clear_EXT_cache_status();
3953:
1.103 albertel 3954: if (!&canview($usec)) {
1.398 albertel 3955: $request->print('<span class="LC_warning">Unable to view requested student.('.$env{'form.student'}.')</span>');
1.324 albertel 3956: $request->print(&show_grading_menu_form($symb));
1.103 albertel 3957: return;
3958: }
1.398 albertel 3959: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.257 albertel 3960: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3961: '</h3>'."\n";
1.382 albertel 3962: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
3963: $result.='<h3> CODE: '.$env{'form.CODE'}.'</h3>'."\n";
3964: } else {
3965: delete($env{'form.CODE'});
3966: }
1.71 ng 3967: &sub_page_js($request);
3968: $request->print($result);
3969:
1.132 bowersj2 3970: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3971: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3972: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3973: if (!$map) {
1.398 albertel 3974: $request->print('<span class="LC_warning">Unable to view requested sequence. ('.$resUrl.')</span>');
1.324 albertel 3975: $request->print(&show_grading_menu_form($symb));
1.288 albertel 3976: return;
3977: }
1.68 ng 3978: my $iterator = $navmap->getIterator($map->map_start(),
3979: $map->map_finish());
3980:
1.71 ng 3981: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3982: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3983: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3984: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3985: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3986: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 3987: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 3988: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3989: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3990:
1.382 albertel 3991: if (defined($env{'form.CODE'})) {
3992: $studentTable.=
3993: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
3994: }
1.381 albertel 3995: my $checkIcon = '<img alt="'.&mt('Check Mark').
3996: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 3997: '/check.gif" height="16" border="0" />';
3998:
1.118 ng 3999: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
4000: ' symbol.'."\n".
1.71 ng 4001: '<table border="0"><tr><td bgcolor="#777777">'.
4002: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 4003: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 4004: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 4005:
1.329 albertel 4006: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4007: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4008: $iterator->next(); # skip the first BEGIN_MAP
4009: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4010: while ($depth > 0) {
1.68 ng 4011: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4012: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4013:
1.385 albertel 4014: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4015: my $parts = $curRes->parts();
1.68 ng 4016: my $title = $curRes->compTitle();
1.71 ng 4017: my $symbx = $curRes->symb();
1.196 albertel 4018: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4019: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4020: $studentTable.='<td valign="top">';
1.382 albertel 4021: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4022: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4023: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4024: undef,'both',\%form);
1.71 ng 4025: } else {
1.382 albertel 4026: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4027: $companswer =~ s|<form(.*?)>||g;
4028: $companswer =~ s|</form>||g;
1.71 ng 4029: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4030: # $companswer =~ s/$1/ /ms;
1.326 albertel 4031: # $request->print('match='.$1."<br />\n");
1.71 ng 4032: # }
1.116 ng 4033: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.326 albertel 4034: $studentTable.=' <b>'.$title.'</b> <br /> <b>Correct answer:</b><br />'.$companswer;
1.71 ng 4035: }
4036:
1.257 albertel 4037: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4038:
1.257 albertel 4039: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4040: if ($record{'version'} eq '') {
1.398 albertel 4041: $studentTable.='<br /> <span class="LC_warning">No recorded submission for this problem</span><br />';
1.71 ng 4042: } else {
1.116 ng 4043: my %responseType = ();
4044: foreach my $partid (@{$parts}) {
1.147 albertel 4045: my @responseIds =$curRes->responseIds($partid);
4046: my @responseType =$curRes->responseType($partid);
4047: my %responseIds;
4048: for (my $i=0;$i<=$#responseIds;$i++) {
4049: $responseIds{$responseIds[$i]}=$responseType[$i];
4050: }
4051: $responseType{$partid} = \%responseIds;
1.116 ng 4052: }
1.148 albertel 4053: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4054:
1.71 ng 4055: }
1.257 albertel 4056: } elsif ($env{'form.lastSub'} eq 'all') {
4057: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4058: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4059: $env{'request.course.id'},
1.71 ng 4060: '','.submission');
4061:
4062: }
1.103 albertel 4063: if (&canmodify($usec)) {
4064: foreach my $partid (@{$parts}) {
4065: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4066: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4067: $question++;
4068: }
1.196 albertel 4069: $prob++;
1.71 ng 4070: }
4071: $studentTable.='</td></tr>';
1.68 ng 4072:
1.103 albertel 4073: }
1.68 ng 4074: $curRes = $iterator->next();
4075: }
4076:
1.381 albertel 4077: $studentTable.='</table></td></tr></table>'."\n".
1.125 ng 4078: '<input type="button" value="Save" '.
1.381 albertel 4079: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4080: '</form>'."\n";
1.324 albertel 4081: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4082: $request->print($studentTable);
4083:
4084: return '';
1.119 ng 4085: }
4086:
4087: sub displaySubByDates {
1.148 albertel 4088: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4089: my $isCODE=0;
1.335 albertel 4090: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4091: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 4092: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
4093: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
4094: '<td><b>Date/Time</b></td>'.
1.224 albertel 4095: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 4096: '<td><b>Submission</b></td>'.
4097: '<td><b>Status </b></td></tr>';
4098: my ($version);
4099: my %mark;
1.148 albertel 4100: my %orders;
1.119 ng 4101: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4102: if (!exists($$record{'1:timestamp'})) {
1.398 albertel 4103: return '<br /> <span class="LC_warning">Nothing submitted - no attempts</span><br />';
1.147 albertel 4104: }
1.335 albertel 4105:
4106: my $interaction;
1.119 ng 4107: for ($version=1;$version<=$$record{'version'};$version++) {
4108: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
1.335 albertel 4109: if (exists($$record{$version.':resource.0.version'})) {
4110: $interaction = $$record{$version.':resource.0.version'};
4111: }
4112:
4113: my $where = ($isTask ? "$version:resource.$interaction"
4114: : "$version:resource");
4115: #&Apache::lonnet::logthis(" got $where");
1.119 ng 4116: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 4117: if ($isCODE) {
4118: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4119: }
1.119 ng 4120: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4121: my @displaySub = ();
4122: foreach my $partid (@{$parts}) {
1.335 albertel 4123: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4124: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4125:
4126:
1.122 ng 4127: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4128: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4129: foreach my $matchKey (@matchKey) {
1.198 albertel 4130: if (exists($$record{$version.':'.$matchKey}) &&
4131: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4132:
4133: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4134: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
4135: #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey});
1.207 albertel 4136: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.398 albertel 4137: $displaySub[0].='<span class="LC_internal_info">(ID '.
4138: $responseId.')</span> <b>';
1.335 albertel 4139: if ($$record{"$where.$partid.tries"} eq '') {
1.147 albertel 4140: $displaySub[0].='Trial not counted';
4141: } else {
4142: $displaySub[0].='Trial '.
1.335 albertel 4143: $$record{"$where.$partid.tries"};
1.147 albertel 4144: }
1.335 albertel 4145: my $responseType=($isTask ? 'Task'
4146: : $responseType->{$partid}->{$responseId});
1.148 albertel 4147: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4148: if (!exists($orders{$partid}->{$responseId})) {
4149: $orders{$partid}->{$responseId}=
4150: &get_order($partid,$responseId,$symb,$uname,$udom);
4151: }
1.147 albertel 4152: $displaySub[0].='</b> '.
1.336 albertel 4153: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4154: }
4155: }
1.335 albertel 4156: if (exists($$record{"$where.$partid.checkedin"})) {
4157: $displaySub[1].='Checked in by '.
4158: $$record{"$where.$partid.checkedin"}.' into slot '.
4159: $$record{"$where.$partid.checkedin.slot"}.
4160: '<br />';
4161: }
4162: if (exists $$record{"$where.$partid.award"}) {
1.207 albertel 4163: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.335 albertel 4164: lc($$record{"$where.$partid.award"}).' '.
4165: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4166: '<br />';
4167: }
1.335 albertel 4168: if (exists $$record{"$where.$partid.regrader"}) {
4169: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4170: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4171: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4172: $displaySub[2].=
4173: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4174: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4175: }
4176: }
4177: # needed because old essay regrader has not parts info
4178: if (exists $$record{"$version:resource.regrader"}) {
4179: $displaySub[2].=$$record{"$version:resource.regrader"};
4180: }
4181: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4182: if ($displaySub[2]) {
4183: $studentTable.='Manually graded by '.$displaySub[2];
4184: }
1.382 albertel 4185: $studentTable.=' </td></tr>';
1.147 albertel 4186:
1.119 ng 4187: }
4188: $studentTable.='</table></td></tr></table>';
4189: return $studentTable;
1.71 ng 4190: }
4191:
4192: sub updateGradeByPage {
4193: my ($request) = shift;
4194:
1.257 albertel 4195: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4196: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4197: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4198: my $pageTitle = $env{'form.page'};
1.103 albertel 4199: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4200: my ($uname,$udom) = split(/:/,$env{'form.student'});
4201: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4202: if (!&canmodify($usec)) {
1.398 albertel 4203: $request->print('<span class="LC_warning">Unable to modify requested student.('.$env{'form.student'}.'</span>');
1.324 albertel 4204: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4205: return;
4206: }
1.398 albertel 4207: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.257 albertel 4208: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4209: '</h3>'."\n";
1.70 ng 4210:
1.68 ng 4211: $request->print($result);
4212:
1.132 bowersj2 4213: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4214: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4215: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4216: if (!$map) {
1.398 albertel 4217: $request->print('<span class="LC_warning">Unable to grade requested sequence. ('.$resUrl.')</span>');
1.324 albertel 4218: my ($symb)=&get_symb($request);
4219: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4220: return;
4221: }
1.71 ng 4222: my $iterator = $navmap->getIterator($map->map_start(),
4223: $map->map_finish());
1.70 ng 4224:
1.71 ng 4225: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 4226: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 4227: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 4228: '<td><b> Title </b></td>'.
4229: '<td><b> Previous Score </b></td>'.
4230: '<td><b> New Score </b></td></tr>';
4231:
4232: $iterator->next(); # skip the first BEGIN_MAP
4233: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4234: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4235: while ($depth > 0) {
1.71 ng 4236: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4237: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4238:
1.385 albertel 4239: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4240: my $parts = $curRes->parts();
1.71 ng 4241: my $title = $curRes->compTitle();
4242: my $symbx = $curRes->symb();
1.196 albertel 4243: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4244: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4245: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4246:
4247: my %newrecord=();
4248: my @displayPts=();
1.269 raeburn 4249: my %aggregate = ();
4250: my $aggregateflag = 0;
1.71 ng 4251: foreach my $partid (@{$parts}) {
1.257 albertel 4252: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4253: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4254:
1.257 albertel 4255: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4256: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4257: my $partial = $newpts/$wgt;
4258: my $score;
4259: if ($partial > 0) {
4260: $score = 'correct_by_override';
1.125 ng 4261: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4262: $score = 'incorrect_by_override';
4263: }
1.257 albertel 4264: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4265: if ($dropMenu eq 'excused') {
1.71 ng 4266: $partial = '';
4267: $score = 'excused';
1.125 ng 4268: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4269: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4270: $newrecord{'resource.'.$partid.'.tries'} = 0;
4271: $newrecord{'resource.'.$partid.'.solved'} = '';
4272: $newrecord{'resource.'.$partid.'.award'} = '';
4273: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4274: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4275: $changeflag++;
4276: $newpts = '';
1.269 raeburn 4277:
4278: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4279: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4280: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4281: if ($aggtries > 0) {
4282: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4283: $aggregateflag = 1;
4284: }
1.71 ng 4285: }
1.324 albertel 4286: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4287: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4288: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4289: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4290: ' <br />';
1.207 albertel 4291: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4292: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4293: ' <br />';
1.71 ng 4294: $question++;
1.380 albertel 4295: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4296:
1.71 ng 4297: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4298: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4299: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4300: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4301:
4302: $changeflag++;
4303: }
4304: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4305: my %record =
4306: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4307: $udom,$uname);
4308:
4309: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4310: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4311: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4312: $newrecord{'resource.CODE'} = '';
4313: }
1.257 albertel 4314: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4315: $udom,$uname);
1.382 albertel 4316: %record = &Apache::lonnet::restore($symbx,
4317: $env{'request.course.id'},
4318: $udom,$uname);
1.380 albertel 4319: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4320: $cdom,$cnum,$udom,$uname);
1.71 ng 4321: }
1.380 albertel 4322:
1.269 raeburn 4323: if ($aggregateflag) {
4324: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4325: $env{'course.'.$env{'request.course.id'}.'.domain'},
4326: $env{'course.'.$env{'request.course.id'}.'.num'});
4327: }
1.125 ng 4328:
1.71 ng 4329: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4330: '<td valign="top">'.$displayPts[1].'</td>'.
4331: '</tr>';
1.68 ng 4332:
1.196 albertel 4333: $prob++;
1.68 ng 4334: }
1.71 ng 4335: $curRes = $iterator->next();
1.68 ng 4336: }
1.98 albertel 4337:
1.71 ng 4338: $studentTable.='</td></tr></table></td></tr></table>';
1.324 albertel 4339: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.76 ng 4340: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4341: 'The scores were changed for '.
4342: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4343: $request->print($grademsg.$studentTable);
1.68 ng 4344:
1.70 ng 4345: return '';
4346: }
4347:
1.72 ng 4348: #-------- end of section for handling grading by page/sequence ---------
4349: #
4350: #-------------------------------------------------------------------
4351:
1.75 albertel 4352: #--------------------Scantron Grading-----------------------------------
4353: #
4354: #------ start of section for handling grading by page/sequence ---------
4355:
1.423 albertel 4356: =pod
4357:
4358: =head1 Bubble sheet grading routines
4359:
1.424 albertel 4360: For this documentation:
4361:
4362: 'scanline' refers to the full line of characters
4363: from the file that we are parsing that represents one entire sheet
4364:
4365: 'bubble line' refers to the data
4366: representing the line of bubbles that are on the physical bubble sheet
4367:
4368:
4369: The overall process is that a scanned in bubble sheet data is uploaded
4370: into a course. When a user wants to grade, they select a
4371: sequence/folder of resources, a file of bubble sheet info, and pick
4372: one of the predefined configurations for what each scanline looks
4373: like.
4374:
4375: Next each scanline is checked for any errors of either 'missing
4376: bubbles' (it's an error because it may have been missed scanned
4377: because too light bubbling), 'double bubble' (each bubble line should
4378: have no more that one letter picked), invalid or duplicated CODE,
4379: invalid student ID
4380:
4381: If the CODE option is used that determines the randomization of the
4382: homework problems, either way the student ID is looked up into a
4383: username:domain.
4384:
4385: During the validation phase the instructor can choose to skip scanlines.
4386:
4387: After the validation phase, there is now 3 bubble sheet files
4388:
4389: scantron_original_filename (unmodified original file)
4390: scantron_corrected_filename (file where the corrected information has replaced the original information)
4391: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4392:
4393: Also there is a separate hash nohist_scantrondata that contains extra
4394: correction information that isn't representable in the bubble sheet
4395: file (see &scantron_getfile() for more information)
4396:
4397: After all scanlines are either valid, marked as valid or skipped, then
4398: foreach line foreach problem in the picked sequence, an ssi request is
4399: made that simulates a user submitting their selected letter(s) against
4400: the homework problem.
1.423 albertel 4401:
4402: =over 4
4403:
4404: =cut
4405:
4406:
4407: =pod
4408:
4409: =item defaultFormData
4410:
4411: Returns html hidden inputs used to hold context/default values.
4412:
4413: Arguments:
4414: $symb - $symb of the current resource
4415:
4416: =cut
1.422 foxr 4417:
1.81 albertel 4418: sub defaultFormData {
1.324 albertel 4419: my ($symb)=@_;
1.81 albertel 4420: return '
1.418 albertel 4421: <input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4422: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4423: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4424: }
4425:
1.423 albertel 4426: =pod
4427:
4428: =item getSequenceDropDown
4429:
4430: Return html dropdown of possible sequences to grade
4431:
4432: Arguments:
4433: $symb - $symb of the current resource
4434:
4435: =cut
1.422 foxr 4436:
1.75 albertel 4437: sub getSequenceDropDown {
1.423 albertel 4438: my ($symb)=@_;
1.75 albertel 4439: my $result='<select name="selectpage">'."\n";
1.423 albertel 4440: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4441: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4442: my $ctr=0;
4443: foreach (@$titles) {
4444: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4445: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4446: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4447: '>'.$showtitle.'</option>'."\n";
4448: $ctr++;
4449: }
4450: $result.= '</select>';
4451: return $result;
4452: }
4453:
1.423 albertel 4454:
4455: =pod
4456:
4457: =item scantron_filenames
4458:
4459: Returns a list of the scantron files in the current course
4460:
4461: =cut
1.422 foxr 4462:
1.202 albertel 4463: sub scantron_filenames {
1.257 albertel 4464: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4465: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4466: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.359 www 4467: &propath($cdom,$cname));
1.202 albertel 4468: my @possiblenames;
1.201 albertel 4469: foreach my $filename (sort(@files)) {
1.157 albertel 4470: ($filename)=split(/&/,$filename);
4471: if ($filename!~/^scantron_orig_/) { next ; }
4472: $filename=~s/^scantron_orig_//;
1.202 albertel 4473: push(@possiblenames,$filename);
4474: }
4475: return @possiblenames;
4476: }
4477:
1.423 albertel 4478: =pod
4479:
4480: =item scantron_uploads
4481:
4482: Returns html drop-down list of scantron files in current course.
4483:
4484: Arguments:
4485: $file2grade - filename to set as selected in the dropdown
4486:
4487: =cut
1.422 foxr 4488:
1.202 albertel 4489: sub scantron_uploads {
1.209 ng 4490: my ($file2grade) = @_;
1.202 albertel 4491: my $result= '<select name="scantron_selectfile">';
4492: $result.="<option></option>";
4493: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4494: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4495: }
4496: $result.="</select>";
4497: return $result;
4498: }
4499:
1.423 albertel 4500: =pod
4501:
4502: =item scantron_scantab
4503:
4504: Returns html drop down of the scantron formats in the scantronformat.tab
4505: file.
4506:
4507: =cut
1.422 foxr 4508:
1.82 albertel 4509: sub scantron_scantab {
4510: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4511: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4512: $result.='<option></option>'."\n";
1.82 albertel 4513: foreach my $line (<$fh>) {
4514: my ($name,$descrip)=split(/:/,$line);
4515: if ($name =~ /^\#/) { next; }
4516: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4517: }
4518: $result.='</select>'."\n";
4519:
4520: return $result;
4521: }
4522:
1.423 albertel 4523: =pod
4524:
4525: =item scantron_CODElist
4526:
4527: Returns html drop down of the saved CODE lists from current course,
4528: generated from earlier printings.
4529:
4530: =cut
1.422 foxr 4531:
1.186 albertel 4532: sub scantron_CODElist {
1.257 albertel 4533: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4534: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4535: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4536: my $namechoice='<option></option>';
1.225 albertel 4537: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4538: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4539: if ($name =~ /^type\0/) { next; }
1.186 albertel 4540: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4541: }
4542: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4543: return $namechoice;
4544: }
4545:
1.423 albertel 4546: =pod
4547:
4548: =item scantron_CODEunique
4549:
4550: Returns the html for "Each CODE to be used once" radio.
4551:
4552: =cut
1.422 foxr 4553:
1.186 albertel 4554: sub scantron_CODEunique {
1.381 albertel 4555: my $result='<span style="white-space: nowrap;">
1.272 albertel 4556: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4557: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 4558: </span>
4559: <span style="white-space: nowrap;">
1.272 albertel 4560: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4561: value="no" />'.&mt('No').' </label>
1.381 albertel 4562: </span>';
1.186 albertel 4563: return $result;
4564: }
1.423 albertel 4565:
4566: =pod
4567:
4568: =item scantron_selectphase
4569:
4570: Generates the initial screen to start the bubble sheet process.
4571: Allows for - starting a grading run.
1.424 albertel 4572: - downloading existing scan data (original, corrected
1.423 albertel 4573: or skipped info)
4574:
4575: - uploading new scan data
4576:
4577: Arguments:
4578: $r - The Apache request object
4579: $file2grade - name of the file that contain the scanned data to score
4580:
4581: =cut
1.186 albertel 4582:
1.75 albertel 4583: sub scantron_selectphase {
1.209 ng 4584: my ($r,$file2grade) = @_;
1.324 albertel 4585: my ($symb)=&get_symb($r);
1.75 albertel 4586: if (!$symb) {return '';}
1.423 albertel 4587: my $sequence_selector=&getSequenceDropDown($symb);
1.324 albertel 4588: my $default_form_data=&defaultFormData($symb);
4589: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4590: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4591: my $format_selector=&scantron_scantab();
1.186 albertel 4592: my $CODE_selector=&scantron_CODElist();
4593: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4594: my $result;
1.422 foxr 4595:
4596: # Chunk of form to prompt for a file to grade and how:
4597:
1.75 albertel 4598: $result.= <<SCANTRONFORM;
1.162 albertel 4599: <table width="100%" border="0">
1.75 albertel 4600: <tr>
1.226 albertel 4601: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4602: <td bgcolor="#777777">
1.203 albertel 4603: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4604: $default_form_data
1.75 albertel 4605: <table width="100%" border="0">
4606: <tr bgcolor="#e6ffff">
1.174 albertel 4607: <td colspan="2">
4608: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4609: </td>
4610: </tr>
4611: <tr bgcolor="#ffffe6">
1.174 albertel 4612: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4613: </tr>
4614: <tr bgcolor="#ffffe6">
1.174 albertel 4615: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4616: </tr>
1.82 albertel 4617: <tr bgcolor="#ffffe6">
1.174 albertel 4618: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4619: </tr>
1.157 albertel 4620: <tr bgcolor="#ffffe6">
1.186 albertel 4621: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4622: </tr>
4623: <tr bgcolor="#ffffe6">
4624: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4625: </tr>
4626: <tr bgcolor="#ffffe6">
1.187 albertel 4627: <td> Options: </td>
4628: <td>
1.272 albertel 4629: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
1.424 albertel 4630: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all existing corrections</label> <br />
1.331 albertel 4631: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
1.187 albertel 4632: </td>
4633: </tr>
4634: <tr bgcolor="#ffffe6">
1.174 albertel 4635: <td colspan="2">
1.265 www 4636: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4637: </td>
4638: </tr>
4639: </table>
1.226 albertel 4640: </td>
4641: </form>
1.162 albertel 4642: </tr>
4643: SCANTRONFORM
4644:
4645: $r->print($result);
4646:
1.257 albertel 4647: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4648: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4649:
1.422 foxr 4650: # Chunk of form to prompt for a scantron file upload.
4651:
1.162 albertel 4652: $r->print(<<SCANTRONFORM);
4653: <tr>
4654: <td bgcolor="#777777">
4655: <table width="100%" border="0">
4656: <tr bgcolor="#e6ffff">
4657: <td>
1.174 albertel 4658: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4659: </td>
4660: </tr>
4661: <tr bgcolor="#ffffe6">
4662: <td>
4663: SCANTRONFORM
1.324 albertel 4664: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 4665: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4666: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4667: $r->print(<<UPLOAD);
4668: <script type="text/javascript" language="javascript">
4669: function checkUpload(formname) {
4670: if (formname.upfile.value == "") {
4671: alert("Please use the browse button to select a file from your local directory.");
4672: return false;
4673: }
4674: formname.submit();
4675: }
4676: </script>
4677:
4678: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4679: $default_form_data
4680: <input name='courseid' type='hidden' value='$cnum' />
4681: <input name='domainid' type='hidden' value='$cdom' />
4682: <input name='command' value='scantronupload_save' type='hidden' />
4683: File to upload:<input type="file" name="upfile" size="50" />
4684: <br />
4685: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4686: </form>
4687: UPLOAD
1.162 albertel 4688:
4689: $r->print(<<SCANTRONFORM);
4690: </td>
4691: </tr>
1.75 albertel 4692: </table>
4693: </td>
4694: </tr>
1.162 albertel 4695: SCANTRONFORM
4696: }
1.422 foxr 4697:
4698: # Chunk of the form that prompts to view a scoring office file,
4699: # corrected file, skipped records in a file.
4700:
1.187 albertel 4701: $r->print(<<SCANTRONFORM);
4702: <tr>
1.226 albertel 4703: <form action='/adm/grades' name='scantron_download'>
4704: <td bgcolor="#777777">
1.379 albertel 4705: $default_form_data
1.187 albertel 4706: <input type="hidden" name="command" value="scantron_download" />
4707: <table width="100%" border="0">
4708: <tr bgcolor="#e6ffff">
4709: <td colspan="2">
4710: <b>Download a scoring office file</b>
4711: </td>
4712: </tr>
4713: <tr bgcolor="#ffffe6">
4714: <td> Filename of scoring office file: </td><td> $file_selector </td>
4715: </tr>
4716: <tr bgcolor="#ffffe6">
4717: <td colspan="2">
1.293 www 4718: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4719: </td>
4720: </tr>
4721: </table>
1.226 albertel 4722: </td>
4723: </form>
1.187 albertel 4724: </tr>
4725: SCANTRONFORM
1.162 albertel 4726:
4727: $r->print(<<SCANTRONFORM);
1.75 albertel 4728: </table>
1.81 albertel 4729: $grading_menu_button
1.75 albertel 4730: SCANTRONFORM
4731:
1.162 albertel 4732: return
1.75 albertel 4733: }
4734:
1.423 albertel 4735: =pod
4736:
4737: =item get_scantron_config
4738:
4739: Parse and return the scantron configuration line selected as a
4740: hash of configuration file fields.
4741:
4742: Arguments:
4743: which - the name of the configuration to parse from the file.
4744:
4745:
4746: Returns:
4747: If the named configuration is not in the file, an empty
4748: hash is returned.
4749: a hash with the fields
4750: name - internal name for the this configuration setup
4751: description - text to display to operator that describes this config
4752: CODElocation - if 0 or the string 'none'
4753: - no CODE exists for this config
4754: if -1 || the string 'letter'
4755: - a CODE exists for this config and is
4756: a string of letters
4757: Unsupported value (but planned for future support)
4758: if a positive integer
4759: - The CODE exists as the first n items from
4760: the question section of the form
4761: if the string 'number'
4762: - The CODE exists for this config and is
4763: a string of numbers
4764: CODEstart - (only matter if a CODE exists) column in the line where
4765: the CODE starts
4766: CODElength - length of the CODE
4767: IDstart - column where the student ID number starts
4768: IDlength - length of the student ID info
4769: Qstart - column where the information from the bubbled
4770: 'questions' start
4771: Qlength - number of columns comprising a single bubble line from
4772: the sheet. (usually either 1 or 10)
1.424 albertel 4773: Qon - either a single character representing the character used
1.423 albertel 4774: to signal a bubble was chosen in the positional setup, or
4775: the string 'letter' if the letter of the chosen bubble is
4776: in the final, or 'number' if a number representing the
4777: chosen bubble is in the file (1->A 0->J)
1.424 albertel 4778: Qoff - the character used to represent that a bubble was
4779: left blank
1.423 albertel 4780: PaperID - if the scanning process generates a unique number for each
4781: sheet scanned the column that this ID number starts in
4782: PaperIDlength - number of columns that comprise the unique ID number
4783: for the sheet of paper
1.424 albertel 4784: FirstName - column that the first name starts in
1.423 albertel 4785: FirstNameLength - number of columns that the first name spans
4786:
4787: LastName - column that the last name starts in
4788: LastNameLength - number of columns that the last name spans
4789:
4790: =cut
1.422 foxr 4791:
1.82 albertel 4792: sub get_scantron_config {
4793: my ($which) = @_;
4794: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4795: my %config;
1.157 albertel 4796: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4797: foreach my $line (<$fh>) {
4798: my ($name,$descrip)=split(/:/,$line);
4799: if ($name ne $which ) { next; }
4800: chomp($line);
4801: my @config=split(/:/,$line);
4802: $config{'name'}=$config[0];
4803: $config{'description'}=$config[1];
4804: $config{'CODElocation'}=$config[2];
4805: $config{'CODEstart'}=$config[3];
4806: $config{'CODElength'}=$config[4];
4807: $config{'IDstart'}=$config[5];
4808: $config{'IDlength'}=$config[6];
4809: $config{'Qstart'}=$config[7];
4810: $config{'Qlength'}=$config[8];
4811: $config{'Qoff'}=$config[9];
4812: $config{'Qon'}=$config[10];
1.157 albertel 4813: $config{'PaperID'}=$config[11];
4814: $config{'PaperIDlength'}=$config[12];
4815: $config{'FirstName'}=$config[13];
4816: $config{'FirstNamelength'}=$config[14];
4817: $config{'LastName'}=$config[15];
4818: $config{'LastNamelength'}=$config[16];
1.82 albertel 4819: last;
4820: }
4821: return %config;
4822: }
4823:
1.423 albertel 4824: =pod
4825:
4826: =item username_to_idmap
4827:
4828: creates a hash keyed by student id with values of the corresponding
4829: student username:domain.
4830:
4831: Arguments:
4832:
4833: $classlist - reference to the class list hash. This is a hash
4834: keyed by student name:domain whose elements are references
1.424 albertel 4835: to arrays containing various chunks of information
1.423 albertel 4836: about the student. (See loncoursedata for more info).
4837:
4838: Returns
4839: %idmap - the constructed hash
4840:
4841: =cut
4842:
1.82 albertel 4843: sub username_to_idmap {
4844: my ($classlist)= @_;
4845: my %idmap;
4846: foreach my $student (keys(%$classlist)) {
4847: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4848: $student;
4849: }
4850: return %idmap;
4851: }
1.423 albertel 4852:
4853: =pod
4854:
1.424 albertel 4855: =item scantron_fixup_scanline
1.423 albertel 4856:
4857: Process a requested correction to a scanline.
4858:
4859: Arguments:
4860: $scantron_config - hash from &get_scantron_config()
4861: $scan_data - hash of correction information
4862: (see &scantron_getfile())
4863: $line - existing scanline
4864: $whichline - line number of the passed in scanline
4865: $field - type of change to process
4866: (either
4867: 'ID' -> correct the student ID number
4868: 'CODE' -> correct the CODE
4869: 'answer' -> fixup the submitted answers)
4870:
4871: $args - hash of additional info,
4872: - 'ID'
4873: 'newid' -> studentID to use in replacement
1.424 albertel 4874: of existing one
1.423 albertel 4875: - 'CODE'
4876: 'CODE_ignore_dup' - set to true if duplicates
4877: should be ignored.
4878: 'CODE' - is new code or 'use_unfound'
1.424 albertel 4879: if the existing unfound code should
1.423 albertel 4880: be used as is
4881: - 'answer'
4882: 'response' - new answer or 'none' if blank
4883: 'question' - the bubble line to change
4884:
4885: Returns:
4886: $line - the modified scanline
4887:
4888: Side effects:
4889: $scan_data - may be updated
4890:
4891: =cut
4892:
1.82 albertel 4893:
1.157 albertel 4894: sub scantron_fixup_scanline {
4895: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
1.423 albertel 4896:
1.157 albertel 4897: if ($field eq 'ID') {
4898: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4899: return ($line,1,'New value too large');
1.157 albertel 4900: }
4901: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4902: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4903: $args->{'newid'});
4904: }
4905: substr($line,$$scantron_config{'IDstart'}-1,
4906: $$scantron_config{'IDlength'})=$args->{'newid'};
4907: if ($args->{'newid'}=~/^\s*$/) {
4908: &scan_data($scan_data,"$whichline.user",
4909: $args->{'username'}.':'.$args->{'domain'});
4910: }
1.186 albertel 4911: } elsif ($field eq 'CODE') {
1.192 albertel 4912: if ($args->{'CODE_ignore_dup'}) {
4913: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4914: }
4915: &scan_data($scan_data,"$whichline.useCODE",'1');
4916: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4917: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4918: return ($line,1,'New CODE value too large');
4919: }
4920: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4921: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4922: }
4923: substr($line,$$scantron_config{'CODEstart'}-1,
4924: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4925: }
1.157 albertel 4926: } elsif ($field eq 'answer') {
4927: my $length=$scantron_config->{'Qlength'};
4928: my $off=$scantron_config->{'Qoff'};
4929: my $on=$scantron_config->{'Qon'};
4930: my $answer=${off}x$length;
4931: if ($args->{'response'} eq 'none') {
4932: &scan_data($scan_data,
4933: "$whichline.no_bubble.".$args->{'question'},'1');
4934: } else {
1.274 albertel 4935: if ($on eq 'letter') {
4936: my @alphabet=('A'..'Z');
4937: $answer=$alphabet[$args->{'response'}];
4938: } elsif ($on eq 'number') {
4939: $answer=$args->{'response'}+1;
1.389 albertel 4940: if ($answer == 10) { $answer = '0'; }
1.274 albertel 4941: } else {
4942: substr($answer,$args->{'response'},1)=$on;
4943: }
1.157 albertel 4944: &scan_data($scan_data,
4945: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4946: }
4947: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4948: substr($line,$where-1,$length)=$answer;
4949: }
4950: return $line;
4951: }
1.423 albertel 4952:
4953: =pod
4954:
4955: =item scan_data
4956:
4957: Edit or look up an item in the scan_data hash.
4958:
4959: Arguments:
4960: $scan_data - The hash (see scantron_getfile)
4961: $key - shorthand of the key to edit (actual key is
1.424 albertel 4962: scantronfilename_key).
1.423 albertel 4963: $data - New value of the hash entry.
4964: $delete - If true, the entry is removed from the hash.
4965:
4966: Returns:
4967: The new value of the hash table field (undefined if deleted).
4968:
4969: =cut
4970:
4971:
1.157 albertel 4972: sub scan_data {
4973: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4974: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4975: if (defined($value)) {
4976: $scan_data->{$filename.'_'.$key} = $value;
4977: }
4978: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4979: return $scan_data->{$filename.'_'.$key};
4980: }
1.423 albertel 4981:
4982: =pod
4983:
4984: =item scantron_parse_scanline
4985:
4986: Decodes a scanline from the selected scantron file
4987:
4988: Arguments:
4989: line - The text of the scantron file line to process
4990: whichline - Line number
4991: scantron_config - Hash describing the format of the scantron lines.
4992: scan_data - Hash of extra information about the scanline
4993: (see scantron_getfile for more information)
4994: just_header - True if should not process question answers but only
4995: the stuff to the left of the answers.
4996: Returns:
4997: Hash containing the result of parsing the scanline
4998:
4999: Keys are all proceeded by the string 'scantron.'
5000:
5001: CODE - the CODE in use for this scanline
5002: useCODE - 1 if the CODE is invalid but it usage has been forced
5003: by the operator
5004: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5005: CODEs were selected, but the usage has been
5006: forced by the operator
5007: ID - student ID
5008: PaperID - if used, the ID number printed on the sheet when the
5009: paper was scanned
5010: FirstName - first name from the sheet
5011: LastName - last name from the sheet
5012:
5013: if just_header was not true these key may also exist
5014:
5015: missingerror - a list of bubbled line numbers that had a blank bubble
5016: that is considered an error (if the operator had already
5017: okayed a blank bubble line as really being blank then
5018: that bubble line number won't appear here.
5019: doubleerror - a list of bubbled line numbers that had more than one
5020: bubble filled in and has not been corrected by the
5021: operator
5022: maxquest - the number of the last bubble line that was parsed
5023:
5024: (<number> starts at 1)
5025: <number>.answer - zero or more letters representing the selected
5026: letters from the scanline for the bubble line
5027: <number>.
5028: if blank there was either no bubble or there where
5029: multiple bubbles, (consult the keys missingerror and
5030: doubleerror if this is an error condition)
5031:
5032: =cut
5033:
1.82 albertel 5034: sub scantron_parse_scanline {
1.423 albertel 5035: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.82 albertel 5036: my %record;
1.422 foxr 5037: my $questions=substr($line,$$scantron_config{'Qstart'}-1); # Answers
5038: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5039: if (!($$scantron_config{'CODElocation'} eq 0 ||
5040: $$scantron_config{'CODElocation'} eq 'none')) {
5041: if ($$scantron_config{'CODElocation'} < 0 ||
5042: $$scantron_config{'CODElocation'} eq 'letter' ||
5043: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5044: $record{'scantron.CODE'}=substr($data,
5045: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5046: $$scantron_config{'CODElength'});
1.191 albertel 5047: if (&scan_data($scan_data,"$whichline.useCODE")) {
5048: $record{'scantron.useCODE'}=1;
5049: }
1.192 albertel 5050: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5051: $record{'scantron.CODE_ignore_dup'}=1;
5052: }
1.82 albertel 5053: } else {
5054: #FIXME interpret first N questions
5055: }
5056: }
1.83 albertel 5057: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5058: $$scantron_config{'IDlength'});
1.157 albertel 5059: $record{'scantron.PaperID'}=
5060: substr($data,$$scantron_config{'PaperID'}-1,
5061: $$scantron_config{'PaperIDlength'});
5062: $record{'scantron.FirstName'}=
5063: substr($data,$$scantron_config{'FirstName'}-1,
5064: $$scantron_config{'FirstNamelength'});
5065: $record{'scantron.LastName'}=
5066: substr($data,$$scantron_config{'LastName'}-1,
5067: $$scantron_config{'LastNamelength'});
1.423 albertel 5068: if ($just_header) { return \%record; }
1.194 albertel 5069:
1.82 albertel 5070: my @alphabet=('A'..'Z');
5071: my $questnum=0;
5072: while ($questions) {
5073: $questnum++;
5074: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
5075: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 5076: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 5077: if ($$scantron_config{'Qon'} eq 'letter') {
1.371 albertel 5078: if ($currentquest eq '?'
5079: || $currentquest eq '*') {
1.274 albertel 5080: push(@{$record{'scantron.doubleerror'}},$questnum);
5081: $record{"scantron.$questnum.answer"}='';
1.389 albertel 5082: } elsif (!defined($currentquest)
1.274 albertel 5083: || $currentquest eq $$scantron_config{'Qoff'}
5084: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 5085: $record{"scantron.$questnum.answer"}='';
5086: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
5087: push(@{$record{"scantron.missingerror"}},$questnum);
5088: }
5089: } else {
5090: $record{"scantron.$questnum.answer"}=$currentquest;
5091: }
5092: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.371 albertel 5093: if ($currentquest eq '?'
5094: || $currentquest eq '*') {
1.274 albertel 5095: push(@{$record{'scantron.doubleerror'}},$questnum);
5096: $record{"scantron.$questnum.answer"}='';
1.389 albertel 5097: } elsif (!defined($currentquest)
5098: || $currentquest eq $$scantron_config{'Qoff'}
5099: || $currentquest !~ /^\d$/) {
1.239 albertel 5100: $record{"scantron.$questnum.answer"}='';
5101: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
5102: push(@{$record{"scantron.missingerror"}},$questnum);
5103: }
5104: } else {
1.371 albertel 5105: # wrap zero back to J
5106: if ($currentquest eq '0') {
5107: $record{"scantron.$questnum.answer"}=
5108: $alphabet[9];
5109: } else {
5110: $record{"scantron.$questnum.answer"}=
5111: $alphabet[$currentquest-1];
5112: }
1.239 albertel 5113: }
1.82 albertel 5114: } else {
1.239 albertel 5115: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
5116: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
5117: $record{"scantron.$questnum.answer"}='';
5118: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
5119: push(@{$record{"scantron.missingerror"}},$questnum);
5120: }
5121: } else {
5122: $record{"scantron.$questnum.answer"}=
5123: $alphabet[length($array[0])];
5124: }
5125: if (scalar(@array) gt 2) {
5126: push(@{$record{'scantron.doubleerror'}},$questnum);
5127: my @ans=@array;
5128: my $i=length($ans[0]);shift(@ans);
5129: while ($#ans) {
5130: $i+=length($ans[0])+1;
5131: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
5132: shift(@ans);
5133: }
5134: }
1.82 albertel 5135: }
5136: }
1.83 albertel 5137: $record{'scantron.maxquest'}=$questnum;
5138: return \%record;
1.82 albertel 5139: }
5140:
1.423 albertel 5141: =pod
5142:
5143: =item scantron_add_delay
5144:
5145: Adds an error message that occurred during the grading phase to a
5146: queue of messages to be shown after grading pass is complete
5147:
5148: Arguments:
1.424 albertel 5149: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5150: $scanline - the scanline that caused the error
5151: $errormesage - the error message
5152: $errorcode - a numeric code for the error
5153:
5154: Side Effects:
1.424 albertel 5155: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5156:
5157: =cut
5158:
1.82 albertel 5159: sub scantron_add_delay {
1.140 albertel 5160: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5161: push(@$delayqueue,
5162: {'line' => $scanline, 'emsg' => $errormessage,
5163: 'ecode' => $errorcode }
5164: );
1.82 albertel 5165: }
5166:
1.423 albertel 5167: =pod
5168:
5169: =item scantron_find_student
5170:
1.424 albertel 5171: Finds the username for the current scanline
5172:
5173: Arguments:
5174: $scantron_record - hash result from scantron_parse_scanline
5175: $scan_data - hash of correction information
5176: (see &scantron_getfile() form more information)
5177: $idmap - hash from &username_to_idmap()
5178: $line - number of current scanline
5179:
5180: Returns:
5181: Either 'username:domain' or undef if unknown
5182:
1.423 albertel 5183: =cut
5184:
1.82 albertel 5185: sub scantron_find_student {
1.157 albertel 5186: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5187: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5188: if ($scanID =~ /^\s*$/) {
5189: return &scan_data($scan_data,"$line.user");
5190: }
1.83 albertel 5191: foreach my $id (keys(%$idmap)) {
1.157 albertel 5192: if (lc($id) eq lc($scanID)) {
5193: return $$idmap{$id};
5194: }
1.83 albertel 5195: }
5196: return undef;
5197: }
5198:
1.423 albertel 5199: =pod
5200:
5201: =item scantron_filter
5202:
1.424 albertel 5203: Filter sub for lonnavmaps, filters out hidden resources if ignore
5204: hidden resources was selected
5205:
1.423 albertel 5206: =cut
5207:
1.83 albertel 5208: sub scantron_filter {
5209: my ($curres)=@_;
1.331 albertel 5210:
5211: if (ref($curres) && $curres->is_problem()) {
5212: # if the user has asked to not have either hidden
5213: # or 'randomout' controlled resources to be graded
5214: # don't include them
5215: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5216: && $curres->randomout) {
5217: return 0;
5218: }
1.83 albertel 5219: return 1;
5220: }
5221: return 0;
1.82 albertel 5222: }
5223:
1.423 albertel 5224: =pod
5225:
5226: =item scantron_process_corrections
5227:
1.424 albertel 5228: Gets correction information out of submitted form data and corrects
5229: the scanline
5230:
1.423 albertel 5231: =cut
5232:
1.157 albertel 5233: sub scantron_process_corrections {
5234: my ($r) = @_;
1.257 albertel 5235: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5236: my ($scanlines,$scan_data)=&scantron_getfile();
5237: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5238: my $which=$env{'form.scantron_line'};
1.200 albertel 5239: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5240: my ($skip,$err,$errmsg);
1.257 albertel 5241: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5242: $skip=1;
1.257 albertel 5243: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5244: my $newstudent=$env{'form.scantron_username'}.':'.
5245: $env{'form.scantron_domain'};
1.157 albertel 5246: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5247: ($line,$err,$errmsg)=
5248: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5249: 'ID',{'newid'=>$newid,
1.257 albertel 5250: 'username'=>$env{'form.scantron_username'},
5251: 'domain'=>$env{'form.scantron_domain'}});
5252: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5253: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5254: my $newCODE;
1.192 albertel 5255: my %args;
1.190 albertel 5256: if ($resolution eq 'use_unfound') {
1.191 albertel 5257: $newCODE='use_unfound';
1.190 albertel 5258: } elsif ($resolution eq 'use_found') {
1.257 albertel 5259: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 5260: } elsif ($resolution eq 'use_typed') {
1.257 albertel 5261: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 5262: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 5263: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 5264: }
1.257 albertel 5265: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 5266: $args{'CODE_ignore_dup'}=1;
5267: }
5268: $args{'CODE'}=$newCODE;
1.186 albertel 5269: ($line,$err,$errmsg)=
5270: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 5271: 'CODE',\%args);
1.257 albertel 5272: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
5273: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 5274: ($line,$err,$errmsg)=
5275: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
5276: $which,'answer',
5277: { 'question'=>$question,
1.257 albertel 5278: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 5279: if ($err) { last; }
5280: }
5281: }
5282: if ($err) {
1.398 albertel 5283: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 5284: } else {
1.200 albertel 5285: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 5286: &scantron_putfile($scanlines,$scan_data);
5287: }
5288: }
5289:
1.423 albertel 5290: =pod
5291:
5292: =item reset_skipping_status
5293:
1.424 albertel 5294: Forgets the current set of remember skipped scanlines (and thus
5295: reverts back to considering all lines in the
5296: scantron_skipped_<filename> file)
5297:
1.423 albertel 5298: =cut
5299:
1.200 albertel 5300: sub reset_skipping_status {
5301: my ($scanlines,$scan_data)=&scantron_getfile();
5302: &scan_data($scan_data,'remember_skipping',undef,1);
5303: &scantron_putfile(undef,$scan_data);
5304: }
5305:
1.423 albertel 5306: =pod
5307:
5308: =item start_skipping
5309:
1.424 albertel 5310: Marks a scanline to be skipped.
5311:
1.423 albertel 5312: =cut
5313:
1.376 albertel 5314: sub start_skipping {
1.200 albertel 5315: my ($scan_data,$i)=@_;
5316: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5317: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
5318: $remembered{$i}=2;
5319: } else {
5320: $remembered{$i}=1;
5321: }
1.200 albertel 5322: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
5323: }
5324:
1.423 albertel 5325: =pod
5326:
5327: =item should_be_skipped
5328:
1.424 albertel 5329: Checks whether a scanline should be skipped.
5330:
1.423 albertel 5331: =cut
5332:
1.200 albertel 5333: sub should_be_skipped {
1.376 albertel 5334: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 5335: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 5336: # not redoing old skips
1.376 albertel 5337: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 5338: return 0;
5339: }
5340: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5341:
5342: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
5343: return 0;
5344: }
1.200 albertel 5345: return 1;
5346: }
5347:
1.423 albertel 5348: =pod
5349:
5350: =item remember_current_skipped
5351:
1.424 albertel 5352: Discovers what scanlines are in the scantron_skipped_<filename>
5353: file and remembers them into scan_data for later use.
5354:
1.423 albertel 5355: =cut
5356:
1.200 albertel 5357: sub remember_current_skipped {
5358: my ($scanlines,$scan_data)=&scantron_getfile();
5359: my %to_remember;
5360: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5361: if ($scanlines->{'skipped'}[$i]) {
5362: $to_remember{$i}=1;
5363: }
5364: }
1.376 albertel 5365:
1.200 albertel 5366: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
5367: &scantron_putfile(undef,$scan_data);
5368: }
5369:
1.423 albertel 5370: =pod
5371:
5372: =item check_for_error
5373:
1.424 albertel 5374: Checks if there was an error when attempting to remove a specific
5375: scantron_.. bubble sheet data file. Prints out an error if
5376: something went wrong.
5377:
1.423 albertel 5378: =cut
5379:
1.200 albertel 5380: sub check_for_error {
5381: my ($r,$result)=@_;
5382: if ($result ne 'ok' && $result ne 'not_found' ) {
1.401 albertel 5383: $r->print("An error occurred ($result) when trying to Remove the existing corrections.");
1.200 albertel 5384: }
5385: }
1.157 albertel 5386:
1.423 albertel 5387: =pod
5388:
5389: =item scantron_warning_screen
5390:
1.424 albertel 5391: Interstitial screen to make sure the operator has selected the
5392: correct options before we start the validation phase.
5393:
1.423 albertel 5394: =cut
5395:
1.203 albertel 5396: sub scantron_warning_screen {
5397: my ($button_text)=@_;
1.257 albertel 5398: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 5399: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 5400: my $CODElist;
1.284 albertel 5401: if ($scantron_config{'CODElocation'} &&
5402: $scantron_config{'CODEstart'} &&
5403: $scantron_config{'CODElength'}) {
5404: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 5405: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 5406: $CODElist=
5407: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
1.373 albertel 5408: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 5409: }
1.203 albertel 5410: return (<<STUFF);
5411: <p>
1.398 albertel 5412: <span class="LC_warning">Please double check the information
5413: below before clicking on '$button_text'</span>
1.203 albertel 5414: </p>
5415: <table>
1.284 albertel 5416: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 5417: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 5418: $CODElist
1.203 albertel 5419: </table>
5420: <br />
5421: <p> If this information is correct, please click on '$button_text'.</p>
5422: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
5423:
5424: <br />
5425: STUFF
5426: }
5427:
1.423 albertel 5428: =pod
5429:
5430: =item scantron_do_warning
5431:
1.424 albertel 5432: Check if the operator has picked something for all required
5433: fields. Error out if something is missing.
5434:
1.423 albertel 5435: =cut
5436:
1.203 albertel 5437: sub scantron_do_warning {
5438: my ($r)=@_;
1.324 albertel 5439: my ($symb)=&get_symb($r);
1.203 albertel 5440: if (!$symb) {return '';}
1.324 albertel 5441: my $default_form_data=&defaultFormData($symb);
1.203 albertel 5442: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 5443: if ( $env{'form.selectpage'} eq '' ||
5444: $env{'form.scantron_selectfile'} eq '' ||
5445: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 5446: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 5447: if ( $env{'form.selectpage'} eq '') {
1.398 albertel 5448: $r->print('<p><span class="LC_error">You have not selected a Sequence to grade</span></p>');
1.237 albertel 5449: }
1.257 albertel 5450: if ( $env{'form.scantron_selectfile'} eq '') {
1.398 albertel 5451: $r->print('<p><span class="LC_error">You have not selected a file that contains the student\'s response data.</span></p>');
1.237 albertel 5452: }
1.257 albertel 5453: if ( $env{'form.scantron_format'} eq '') {
1.398 albertel 5454: $r->print('<p><span class="LC_error">You have not selected a the format of the student\'s response data.</span></p>');
1.237 albertel 5455: }
5456: } else {
1.265 www 5457: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 5458: $r->print(<<STUFF);
1.203 albertel 5459: $warning
1.265 www 5460: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 5461: <input type="hidden" name="command" value="scantron_validate" />
5462: STUFF
1.237 albertel 5463: }
1.352 albertel 5464: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 5465: return '';
5466: }
5467:
1.423 albertel 5468: =pod
5469:
5470: =item scantron_form_start
5471:
1.424 albertel 5472: html hidden input for remembering all selected grading options
5473:
1.423 albertel 5474: =cut
5475:
1.203 albertel 5476: sub scantron_form_start {
5477: my ($max_bubble)=@_;
5478: my $result= <<SCANTRONFORM;
5479: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 5480: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
5481: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
5482: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 5483: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 5484: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
5485: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
5486: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
5487: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 5488: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 5489: SCANTRONFORM
5490: return $result;
5491: }
5492:
1.423 albertel 5493: =pod
5494:
5495: =item scantron_validate_file
5496:
1.424 albertel 5497: Dispatch routine for doing validation of a bubble sheet data file.
5498:
5499: Also processes any necessary information resets that need to
5500: occur before validation begins (ignore previous corrections,
5501: restarting the skipped records processing)
5502:
1.423 albertel 5503: =cut
5504:
1.157 albertel 5505: sub scantron_validate_file {
5506: my ($r) = @_;
1.324 albertel 5507: my ($symb)=&get_symb($r);
1.157 albertel 5508: if (!$symb) {return '';}
1.324 albertel 5509: my $default_form_data=&defaultFormData($symb);
1.200 albertel 5510:
5511: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 5512: # them when doing the corrections reset
1.257 albertel 5513: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 5514: &reset_skipping_status();
5515: }
1.257 albertel 5516: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 5517: &remember_current_skipped();
1.257 albertel 5518: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 5519: }
5520:
1.257 albertel 5521: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 5522: &check_for_error($r,&scantron_remove_file('corrected'));
5523: &check_for_error($r,&scantron_remove_file('skipped'));
5524: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 5525: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 5526: }
1.200 albertel 5527:
1.257 albertel 5528: if ($env{'form.scantron_corrections'}) {
1.157 albertel 5529: &scantron_process_corrections($r);
5530: }
1.424 albertel 5531: $r->print("<p>Gathering necessary info.</p>");$r->rflush();
1.157 albertel 5532: #get the student pick code ready
5533: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 5534: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 5535: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 5536: $r->print($result);
5537:
1.334 albertel 5538: my @validate_phases=( 'sequence',
5539: 'ID',
1.157 albertel 5540: 'CODE',
5541: 'doublebubble',
5542: 'missingbubbles');
1.257 albertel 5543: if (!$env{'form.validatepass'}) {
5544: $env{'form.validatepass'} = 0;
1.157 albertel 5545: }
1.257 albertel 5546: my $currentphase=$env{'form.validatepass'};
1.157 albertel 5547:
5548: my $stop=0;
5549: while (!$stop && $currentphase < scalar(@validate_phases)) {
5550: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
5551: $r->rflush();
5552: my $which="scantron_validate_".$validate_phases[$currentphase];
5553: {
5554: no strict 'refs';
5555: ($stop,$currentphase)=&$which($r,$currentphase);
5556: }
5557: }
5558: if (!$stop) {
1.203 albertel 5559: my $warning=&scantron_warning_screen('Start Grading');
5560: $r->print(<<STUFF);
5561: Validation process complete.<br />
5562: $warning
5563: <input type="submit" name="submit" value="Start Grading" />
5564: <input type="hidden" name="command" value="scantron_process" />
5565: STUFF
5566:
1.157 albertel 5567: } else {
5568: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
5569: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
5570: }
5571: if ($stop) {
1.334 albertel 5572: if ($validate_phases[$currentphase] eq 'sequence') {
5573: $r->print('<input type="submit" name="submit" value="Ignore -> " />');
5574: $r->print(' this error <br />');
5575:
5576: $r->print(" <p>Or click the 'Grading Menu' button to start over.</p>");
5577: } else {
5578: $r->print('<input type="submit" name="submit" value="Continue ->" />');
5579: $r->print(' using corrected info <br />');
5580: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
5581: $r->print(" this scanline saving it for later.");
5582: }
1.157 albertel 5583: }
1.352 albertel 5584: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 5585: return '';
5586: }
5587:
1.423 albertel 5588:
5589: =pod
5590:
5591: =item scantron_remove_file
5592:
1.424 albertel 5593: Removes the requested bubble sheet data file, makes sure that
5594: scantron_original_<filename> is never removed
5595:
5596:
1.423 albertel 5597: =cut
5598:
1.200 albertel 5599: sub scantron_remove_file {
1.192 albertel 5600: my ($which)=@_;
1.257 albertel 5601: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5602: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5603: my $file='scantron_';
1.200 albertel 5604: if ($which eq 'corrected' || $which eq 'skipped') {
5605: $file.=$which.'_';
1.192 albertel 5606: } else {
5607: return 'refused';
5608: }
1.257 albertel 5609: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 5610: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
5611: }
5612:
1.423 albertel 5613:
5614: =pod
5615:
5616: =item scantron_remove_scan_data
5617:
1.424 albertel 5618: Removes all scan_data correction for the requested bubble sheet
5619: data file. (In the case that both the are doing skipped records we need
5620: to remember the old skipped lines for the time being so that element
5621: persists for a while.)
5622:
1.423 albertel 5623: =cut
5624:
1.200 albertel 5625: sub scantron_remove_scan_data {
1.257 albertel 5626: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5627: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5628: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
5629: my @todelete;
1.257 albertel 5630: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 5631: foreach my $key (@keys) {
5632: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 5633: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 5634: $key=~/remember_skipping/) {
5635: next;
5636: }
1.192 albertel 5637: push(@todelete,$key);
5638: }
5639: }
1.200 albertel 5640: my $result;
1.192 albertel 5641: if (@todelete) {
1.200 albertel 5642: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 5643: }
5644: return $result;
5645: }
5646:
1.423 albertel 5647:
5648: =pod
5649:
5650: =item scantron_getfile
5651:
1.424 albertel 5652: Fetches the requested bubble sheet data file (all 3 versions), and
5653: the scan_data hash
5654:
5655: Arguments:
5656: None
5657:
5658: Returns:
5659: 2 hash references
5660:
5661: - first one has
5662: orig -
5663: corrected -
5664: skipped - each of which points to an array ref of the specified
5665: file broken up into individual lines
5666: count - number of scanlines
5667:
5668: - second is the scan_data hash possible keys are
1.425 ! albertel 5669: ($number refers to scanline numbered $number and thus the key affects
! 5670: only that scanline
! 5671: $bubline refers to the specific bubble line element and the aspects
! 5672: refers to that specific bubble line element)
! 5673:
! 5674: $number.user - username:domain to use
! 5675: $number.CODE_ignore_dup
! 5676: - ignore the duplicate CODE error
! 5677: $number.useCODE
! 5678: - use the CODE in the scanline as is
! 5679: $number.no_bubble.$bubline
! 5680: - it is valid that there is no bubbled in bubble
! 5681: at $number $bubline
! 5682: remember_skipping
! 5683: - a frozen hash containing keys of $number and values
! 5684: of either
! 5685: 1 - we are on a 'do skipped records pass' and plan
! 5686: on processing this line
! 5687: 2 - we are on a 'do skipped records pass' and this
! 5688: scanline has been marked to skip yet again
1.424 albertel 5689:
1.423 albertel 5690: =cut
5691:
1.157 albertel 5692: sub scantron_getfile {
1.200 albertel 5693: #FIXME really would prefer a scantron directory
1.257 albertel 5694: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5695: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 5696: my $lines;
5697: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5698: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 5699: my %scanlines;
5700: $scanlines{'orig'}=[(split("\n",$lines,-1))];
5701: my $temp=$scanlines{'orig'};
5702: $scanlines{'count'}=$#$temp;
5703:
5704: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5705: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 5706: if ($lines eq '-1') {
5707: $scanlines{'corrected'}=[];
5708: } else {
5709: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
5710: }
5711: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5712: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 5713: if ($lines eq '-1') {
5714: $scanlines{'skipped'}=[];
5715: } else {
5716: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
5717: }
1.175 albertel 5718: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 5719: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
5720: my %scan_data = @tmp;
5721: return (\%scanlines,\%scan_data);
5722: }
5723:
1.423 albertel 5724: =pod
5725:
5726: =item lonnet_putfile
5727:
1.424 albertel 5728: Wrapper routine to call &Apache::lonnet::finishuserfileupload
5729:
5730: Arguments:
5731: $contents - data to store
5732: $filename - filename to store $contents into
5733:
5734: Returns:
5735: result value from &Apache::lonnet::finishuserfileupload
5736:
1.423 albertel 5737: =cut
5738:
1.157 albertel 5739: sub lonnet_putfile {
5740: my ($contents,$filename)=@_;
1.257 albertel 5741: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5742: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5743: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 5744: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 5745:
5746: }
5747:
1.423 albertel 5748: =pod
5749:
5750: =item scantron_putfile
5751:
1.424 albertel 5752: Stores the current version of the bubble sheet data files, and the
5753: scan_data hash. (Does not modify the original version only the
5754: corrected and skipped versions.
5755:
5756: Arguments:
5757: $scanlines - hash ref that looks like the first return value from
5758: &scantron_getfile()
5759: $scan_data - hash ref that looks like the second return value from
5760: &scantron_getfile()
5761:
1.423 albertel 5762: =cut
5763:
1.157 albertel 5764: sub scantron_putfile {
5765: my ($scanlines,$scan_data) = @_;
1.200 albertel 5766: #FIXME really would prefer a scantron directory
1.257 albertel 5767: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5768: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 5769: if ($scanlines) {
5770: my $prefix='scantron_';
1.157 albertel 5771: # no need to update orig, shouldn't change
5772: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 5773: # $env{'form.scantron_selectfile'});
1.200 albertel 5774: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
5775: $prefix.'corrected_'.
1.257 albertel 5776: $env{'form.scantron_selectfile'});
1.200 albertel 5777: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
5778: $prefix.'skipped_'.
1.257 albertel 5779: $env{'form.scantron_selectfile'});
1.200 albertel 5780: }
1.175 albertel 5781: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 5782: }
5783:
1.423 albertel 5784: =pod
5785:
5786: =item scantron_get_line
5787:
1.424 albertel 5788: Returns the correct version of the scanline
5789:
5790: Arguments:
5791: $scanlines - hash ref that looks like the first return value from
5792: &scantron_getfile()
5793: $scan_data - hash ref that looks like the second return value from
5794: &scantron_getfile()
5795: $i - number of the requested line (starts at 0)
5796:
5797: Returns:
5798: A scanline, (either the original or the corrected one if it
5799: exists), or undef if the requested scanline should be
5800: skipped. (Either because it's an skipped scanline, or it's an
5801: unskipped scanline and we are not doing a 'do skipped scanlines'
5802: pass.
5803:
1.423 albertel 5804: =cut
5805:
1.157 albertel 5806: sub scantron_get_line {
1.200 albertel 5807: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 5808: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
5809: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 5810: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
5811: return $scanlines->{'orig'}[$i];
5812: }
5813:
1.423 albertel 5814: =pod
5815:
5816: =item scantron_todo_count
5817:
1.424 albertel 5818: Counts the number of scanlines that need processing.
5819:
5820: Arguments:
5821: $scanlines - hash ref that looks like the first return value from
5822: &scantron_getfile()
5823: $scan_data - hash ref that looks like the second return value from
5824: &scantron_getfile()
5825:
5826: Returns:
5827: $count - number of scanlines to process
5828:
1.423 albertel 5829: =cut
5830:
1.200 albertel 5831: sub get_todo_count {
5832: my ($scanlines,$scan_data)=@_;
5833: my $count=0;
5834: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5835: my $line=&scantron_get_line($scanlines,$scan_data,$i);
5836: if ($line=~/^[\s\cz]*$/) { next; }
5837: $count++;
5838: }
5839: return $count;
5840: }
5841:
1.423 albertel 5842: =pod
5843:
5844: =item scantron_put_line
5845:
1.424 albertel 5846: Updates the 'corrected' or 'skipped' versions of the bubble sheet
5847: data file.
5848:
5849: Arguments:
5850: $scanlines - hash ref that looks like the first return value from
5851: &scantron_getfile()
5852: $scan_data - hash ref that looks like the second return value from
5853: &scantron_getfile()
5854: $i - line number to update
5855: $newline - contents of the updated scanline
5856: $skip - if true make the line for skipping and update the
5857: 'skipped' file
5858:
1.423 albertel 5859: =cut
5860:
1.157 albertel 5861: sub scantron_put_line {
1.200 albertel 5862: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 5863: if ($skip) {
5864: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 5865: &start_skipping($scan_data,$i);
1.157 albertel 5866: return;
5867: }
5868: $scanlines->{'corrected'}[$i]=$newline;
5869: }
5870:
1.423 albertel 5871: =pod
5872:
5873: =item scantron_clear_skip
5874:
1.424 albertel 5875: Remove a line from the 'skipped' file
5876:
5877: Arguments:
5878: $scanlines - hash ref that looks like the first return value from
5879: &scantron_getfile()
5880: $scan_data - hash ref that looks like the second return value from
5881: &scantron_getfile()
5882: $i - line number to update
5883:
1.423 albertel 5884: =cut
5885:
1.376 albertel 5886: sub scantron_clear_skip {
5887: my ($scanlines,$scan_data,$i)=@_;
5888: if (exists($scanlines->{'skipped'}[$i])) {
5889: undef($scanlines->{'skipped'}[$i]);
5890: return 1;
5891: }
5892: return 0;
5893: }
5894:
1.423 albertel 5895: =pod
5896:
5897: =item scantron_filter_not_exam
5898:
1.424 albertel 5899: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
5900: filter out resources that are not marked as 'exam' mode
5901:
1.423 albertel 5902: =cut
5903:
1.334 albertel 5904: sub scantron_filter_not_exam {
5905: my ($curres)=@_;
5906:
5907: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
5908: # if the user has asked to not have either hidden
5909: # or 'randomout' controlled resources to be graded
5910: # don't include them
5911: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5912: && $curres->randomout) {
5913: return 0;
5914: }
5915: return 1;
5916: }
5917: return 0;
5918: }
5919:
1.423 albertel 5920: =pod
5921:
5922: =item scantron_validate_sequence
5923:
1.424 albertel 5924: Validates the selected sequence, checking for resource that are
5925: not set to exam mode.
5926:
1.423 albertel 5927: =cut
5928:
1.334 albertel 5929: sub scantron_validate_sequence {
5930: my ($r,$currentphase) = @_;
5931:
5932: my $navmap=Apache::lonnavmaps::navmap->new();
5933: my (undef,undef,$sequence)=
5934: &Apache::lonnet::decode_symb($env{'form.selectpage'});
5935:
5936: my $map=$navmap->getResourceByUrl($sequence);
5937:
5938: $r->print('<input type="hidden" name="validate_sequence_exam"
5939: value="ignore" />');
5940: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
5941: my @resources=
5942: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
5943: if (@resources) {
1.357 banghart 5944: $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 5945: return (1,$currentphase);
5946: }
5947: }
5948:
5949: return (0,$currentphase+1);
5950: }
5951:
1.423 albertel 5952: =pod
5953:
5954: =item scantron_validate_ID
5955:
1.424 albertel 5956: Validates all scanlines in the selected file to not have any
5957: invalid or underspecified student IDs
5958:
1.423 albertel 5959: =cut
5960:
1.157 albertel 5961: sub scantron_validate_ID {
5962: my ($r,$currentphase) = @_;
5963:
5964: #get student info
5965: my $classlist=&Apache::loncoursedata::get_classlist();
5966: my %idmap=&username_to_idmap($classlist);
5967:
5968: #get scantron line setup
1.257 albertel 5969: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5970: my ($scanlines,$scan_data)=&scantron_getfile();
5971:
5972: my %found=('ids'=>{},'usernames'=>{});
5973: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5974: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5975: if ($line=~/^[\s\cz]*$/) { next; }
5976: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5977: $scan_data);
5978: my $id=$$scan_record{'scantron.ID'};
5979: my $found;
5980: foreach my $checkid (keys(%idmap)) {
5981: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
5982: }
5983: if ($found) {
5984: my $username=$idmap{$found};
5985: if ($found{'ids'}{$found}) {
5986: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5987: $line,'duplicateID',$found);
1.194 albertel 5988: return(1,$currentphase);
1.157 albertel 5989: } elsif ($found{'usernames'}{$username}) {
5990: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5991: $line,'duplicateID',$username);
1.194 albertel 5992: return(1,$currentphase);
1.157 albertel 5993: }
1.186 albertel 5994: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 5995: $found{'ids'}{$found}++;
5996: $found{'usernames'}{$username}++;
5997: } else {
5998: if ($id =~ /^\s*$/) {
1.158 albertel 5999: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6000: if (defined($username) && $found{'usernames'}{$username}) {
6001: &scantron_get_correction($r,$i,$scan_record,
6002: \%scantron_config,
6003: $line,'duplicateID',$username);
1.194 albertel 6004: return(1,$currentphase);
1.157 albertel 6005: } elsif (!defined($username)) {
6006: &scantron_get_correction($r,$i,$scan_record,
6007: \%scantron_config,
6008: $line,'incorrectID');
1.194 albertel 6009: return(1,$currentphase);
1.157 albertel 6010: }
6011: $found{'usernames'}{$username}++;
6012: } else {
6013: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6014: $line,'incorrectID');
1.194 albertel 6015: return(1,$currentphase);
1.157 albertel 6016: }
6017: }
6018: }
6019:
6020: return (0,$currentphase+1);
6021: }
6022:
1.423 albertel 6023: =pod
6024:
6025: =item scantron_get_correction
6026:
1.424 albertel 6027: Builds the interface screen to interact with the operator to fix a
6028: specific error condition in a specific scanline
6029:
6030: Arguments:
6031: $r - Apache request object
6032: $i - number of the current scanline
6033: $scan_record - hash ref as returned from &scantron_parse_scanline()
6034: $scan_config - hash ref as returned from &get_scantron_config()
6035: $line - full contents of the current scanline
6036: $error - error condition, valid values are
6037: 'incorrectCODE', 'duplicateCODE',
6038: 'doublebubble', 'missingbubble',
6039: 'duplicateID', 'incorrectID'
6040: $arg - extra information needed
6041: For errors:
6042: - duplicateID - paper number that this studentID was seen before on
6043: - duplicateCODE - array ref of the paper numbers this CODE was
6044: seen on before
6045: - incorrectCODE - current incorrect CODE
6046: - doublebubble - array ref of the bubble lines that have double
6047: bubble errors
6048: - missingbubble - array ref of the bubble lines that have missing
6049: bubble errors
6050:
1.423 albertel 6051: =cut
6052:
1.157 albertel 6053: sub scantron_get_correction {
6054: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
6055:
6056: #FIXME in the case of a duplicated ID the previous line, probaly need
6057: #to show both the current line and the previous one and allow skipping
6058: #the previous one or the current one
6059:
1.161 albertel 6060: $r->print("<p><b>An error was detected ($error)</b>");
1.333 albertel 6061: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.157 albertel 6062: $r->print(" for PaperID <tt>".
6063: $$scan_record{'scantron.PaperID'}."</tt> \n");
6064: } else {
6065: $r->print(" in scanline $i <pre>".
6066: $line."</pre> \n");
6067: }
1.242 albertel 6068: my $message="<p>The ID on the form is <tt>".
6069: $$scan_record{'scantron.ID'}."</tt><br />\n".
6070: "The name on the paper is ".
6071: $$scan_record{'scantron.LastName'}.",".
6072: $$scan_record{'scantron.FirstName'}."</p>";
6073:
1.157 albertel 6074: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6075: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
6076: if ($error =~ /ID$/) {
1.186 albertel 6077: if ($error eq 'incorrectID') {
1.157 albertel 6078: $r->print("The encoded ID is not in the classlist</p>\n");
6079: } elsif ($error eq 'duplicateID') {
6080: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
6081: }
1.242 albertel 6082: $r->print($message);
1.157 albertel 6083: $r->print("<p>How should I handle this? <br /> \n");
6084: $r->print("\n<ul><li> ");
6085: #FIXME it would be nice if this sent back the user ID and
6086: #could do partial userID matches
6087: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6088: 'scantron_username','scantron_domain'));
6089: $r->print(": <input type='text' name='scantron_username' value='' />");
6090: $r->print("\n@".
1.257 albertel 6091: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6092:
6093: $r->print('</li>');
1.186 albertel 6094: } elsif ($error =~ /CODE$/) {
6095: if ($error eq 'incorrectCODE') {
1.187 albertel 6096: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 6097: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 6098: $r->print("</p><p>The encoded CODE has also been used by a previous paper ".join(', ',@{$arg}).", and CODEs are supposed to be unique</p>\n");
1.186 albertel 6099: }
1.224 albertel 6100: $r->print("<p>The CODE on the form is <tt>'".
6101: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 6102: $r->print($message);
1.186 albertel 6103: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 6104: $r->print("\n<br /> ");
1.194 albertel 6105: my $i=0;
1.273 albertel 6106: if ($error eq 'incorrectCODE'
6107: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6108: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6109: if ($closest > 0) {
6110: foreach my $testcode (@{$closest}) {
6111: my $checked='';
1.401 albertel 6112: if (!$i) { $checked=' checked="checked" '; }
1.278 albertel 6113: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked /> Use the similar CODE <b><tt>".$testcode."</tt></b> instead.</label><input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
6114: $r->print("\n<br />");
6115: $i++;
6116: }
1.194 albertel 6117: }
6118: }
1.273 albertel 6119: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.401 albertel 6120: my $checked; if (!$i) { $checked=' checked="checked" '; }
1.273 albertel 6121: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_unfound' $checked /> Use the CODE <b><tt>".$$scan_record{'scantron.CODE'}."</tt></b> that is was on the paper, ignoring the error.</label>");
6122: $r->print("\n<br />");
6123: }
1.194 albertel 6124:
1.188 albertel 6125: $r->print(<<ENDSCRIPT);
6126: <script type="text/javascript">
6127: function change_radio(field) {
1.190 albertel 6128: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6129: var i;
6130: for (i=0;i<slct.length;i++) {
6131: if (slct[i].value==field) { slct[i].checked=true; }
6132: }
6133: }
6134: </script>
6135: ENDSCRIPT
1.187 albertel 6136: my $href="/adm/pickcode?".
1.359 www 6137: "form=".&escape("scantronupload").
6138: "&scantron_format=".&escape($env{'form.scantron_format'}).
6139: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6140: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6141: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6142: if ($env{'form.scantron_CODElist'} =~ /\S/) {
6143: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it.</label> Selected CODE is <input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />");
6144: $r->print("\n<br />");
6145: }
1.272 albertel 6146: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_typed' /> Use </label><input type='text' size='8' name='scantron_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" /> as the CODE.");
1.187 albertel 6147: $r->print("\n<br /><br />");
1.157 albertel 6148: } elsif ($error eq 'doublebubble') {
6149: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
6150: $r->print('<input type="hidden" name="scantron_questions" value="'.
6151: join(',',@{$arg}).'" />');
1.242 albertel 6152: $r->print($message);
1.157 albertel 6153: $r->print("<p>Please indicate which bubble should be used for grading</p>");
6154: foreach my $question (@{$arg}) {
6155: my $selected=$$scan_record{"scantron.$question.answer"};
1.422 foxr 6156: &scantron_bubble_selector($r,$scan_config,$question,
6157: split('',$selected));
1.157 albertel 6158: }
6159: } elsif ($error eq 'missingbubble') {
6160: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 6161: $r->print($message);
1.157 albertel 6162: $r->print("<p>Please indicate which bubble should be used for grading</p>");
6163: $r->print("Some questions have no scanned bubbles\n");
6164: $r->print('<input type="hidden" name="scantron_questions" value="'.
6165: join(',',@{$arg}).'" />');
6166: foreach my $question (@{$arg}) {
6167: my $selected=$$scan_record{"scantron.$question.answer"};
6168: &scantron_bubble_selector($r,$scan_config,$question);
6169: }
6170: } else {
6171: $r->print("\n<ul>");
6172: }
6173: $r->print("\n</li></ul>");
6174:
6175: }
1.423 albertel 6176:
6177: =pod
6178:
6179: =item scantron_bubble_selector
6180:
6181: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 6182: possibly showing the existing the selected bubbles if known
1.423 albertel 6183:
6184: Arguments:
6185: $r - Apache request object
6186: $scan_config - hash from &get_scantron_config()
6187: $quest - number of the bubble line to make a corrector for
6188: $selected - array of letters of previously selected bubbles
6189: $lines - if present, number of bubble lines to show
6190:
6191: =cut
6192:
1.157 albertel 6193: sub scantron_bubble_selector {
1.422 foxr 6194: my ($r,$scan_config,$quest,@selected, $lines)=@_;
1.157 albertel 6195: my $max=$$scan_config{'Qlength'};
1.274 albertel 6196:
6197: my $scmode=$$scan_config{'Qon'};
6198: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
6199:
1.422 foxr 6200:
6201: if (!defined($lines)) {
6202: $lines = 1;
6203: }
6204: my $total_lines = $lines*2;
1.157 albertel 6205: my @alphabet=('A'..'Z');
1.422 foxr 6206: $r->print("<table border='1'><tr><td rowspan='".$total_lines."'>$quest</td>");
6207:
6208: for (my $l = 0; $l < $lines; $l++) {
6209: if ($l != 0) {
6210: $r->print('<tr>');
6211: }
6212:
6213: # FIXME: This loop probably has to be considerably more clever for
6214: # multiline bubbles: User can multibubble by having bubbles in
6215: # several lines. User can skip lines legitimately etc. etc.
6216:
6217: for (my $i=0;$i<$max;$i++) {
6218: $r->print("\n".'<td align="center">');
6219: if ($selected[0] eq $alphabet[$i]) {
6220: $r->print('X');
6221: shift(@selected) ;
6222: } else {
6223: $r->print(' ');
6224: }
6225: $r->print('</td>');
6226:
6227: }
6228:
6229: if ($l == 0) {
6230: my $lspan = $total_lines * 2; # 2 table rows per bubble line.
6231:
6232: $r->print('<td rowspan='.$lspan.'><label><input type="radio" name="scantron_correct_Q_'.
6233: $quest.'" value="none" /> No bubble </label></td>');
6234:
6235: }
6236:
6237: $r->print('</tr><tr>');
6238:
6239: # FIXME: This may have to be a bit more clever for
6240: # multiline questions (different values e.g..).
6241:
6242: for (my $i=0;$i<$max;$i++) {
6243: $r->print("\n".
6244: '<td><label><input type="radio" name="scantron_correct_Q_'.
6245: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
6246: }
6247: $r->print('</tr>');
6248:
6249:
1.157 albertel 6250: }
1.422 foxr 6251: $r->print('</table>');
1.157 albertel 6252: }
6253:
1.423 albertel 6254: =pod
6255:
6256: =item num_matches
6257:
1.424 albertel 6258: Counts the number of characters that are the same between the two arguments.
6259:
6260: Arguments:
6261: $orig - CODE from the scanline
6262: $code - CODE to match against
6263:
6264: Returns:
6265: $count - integer count of the number of same characters between the
6266: two arguments
6267:
1.423 albertel 6268: =cut
6269:
1.194 albertel 6270: sub num_matches {
6271: my ($orig,$code) = @_;
6272: my @code=split(//,$code);
6273: my @orig=split(//,$orig);
6274: my $same=0;
6275: for (my $i=0;$i<scalar(@code);$i++) {
6276: if ($code[$i] eq $orig[$i]) { $same++; }
6277: }
6278: return $same;
6279: }
6280:
1.423 albertel 6281: =pod
6282:
6283: =item scantron_get_closely_matching_CODEs
6284:
1.424 albertel 6285: Cycles through all CODEs and finds the set that has the greatest
6286: number of same characters as the provided CODE
6287:
6288: Arguments:
6289: $allcodes - hash ref returned by &get_codes()
6290: $CODE - CODE from the current scanline
6291:
6292: Returns:
6293: 2 element list
6294: - first elements is number of how closely matching the best fit is
6295: (5 means best set has 5 matching characters)
6296: - second element is an arrary ref containing the set of valid CODEs
6297: that best fit the passed in CODE
6298:
1.423 albertel 6299: =cut
6300:
1.194 albertel 6301: sub scantron_get_closely_matching_CODEs {
6302: my ($allcodes,$CODE)=@_;
6303: my @CODEs;
6304: foreach my $testcode (sort(keys(%{$allcodes}))) {
6305: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
6306: }
6307:
6308: return ($#CODEs,$CODEs[-1]);
6309: }
6310:
1.423 albertel 6311: =pod
6312:
6313: =item get_codes
6314:
1.424 albertel 6315: Builds a hash which has keys of all of the valid CODEs from the selected
6316: set of remembered CODEs.
6317:
6318: Arguments:
6319: $old_name - name of the set of remembered CODEs
6320: $cdom - domain of the course
6321: $cnum - internal course name
6322:
6323: Returns:
6324: %allcodes - keys are the valid CODEs, values are all 1
6325:
1.423 albertel 6326: =cut
6327:
1.194 albertel 6328: sub get_codes {
1.280 foxr 6329: my ($old_name, $cdom, $cnum) = @_;
6330: if (!$old_name) {
6331: $old_name=$env{'form.scantron_CODElist'};
6332: }
6333: if (!$cdom) {
6334: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
6335: }
6336: if (!$cnum) {
6337: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
6338: }
1.278 albertel 6339: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
6340: $cdom,$cnum);
6341: my %allcodes;
6342: if ($result{"type\0$old_name"} eq 'number') {
6343: %allcodes=map {($_,1)} split(',',$result{$old_name});
6344: } else {
6345: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
6346: }
1.194 albertel 6347: return %allcodes;
6348: }
6349:
1.423 albertel 6350: =pod
6351:
6352: =item scantron_validate_CODE
6353:
1.424 albertel 6354: Validates all scanlines in the selected file to not have any
6355: invalid or underspecified CODEs and that none of the codes are
6356: duplicated if this was requested.
6357:
1.423 albertel 6358: =cut
6359:
1.157 albertel 6360: sub scantron_validate_CODE {
6361: my ($r,$currentphase) = @_;
1.257 albertel 6362: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 6363: if ($scantron_config{'CODElocation'} &&
6364: $scantron_config{'CODEstart'} &&
6365: $scantron_config{'CODElength'}) {
1.257 albertel 6366: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 6367: &FIXME_blow_up()
6368: }
6369: } else {
6370: return (0,$currentphase+1);
6371: }
6372:
6373: my %usedCODEs;
6374:
1.194 albertel 6375: my %allcodes=&get_codes();
1.186 albertel 6376:
6377: my ($scanlines,$scan_data)=&scantron_getfile();
6378: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6379: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 6380: if ($line=~/^[\s\cz]*$/) { next; }
6381: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6382: $scan_data);
6383: my $CODE=$$scan_record{'scantron.CODE'};
6384: my $error=0;
1.224 albertel 6385: if (!&Apache::lonnet::validCODE($CODE)) {
6386: &scantron_get_correction($r,$i,$scan_record,
6387: \%scantron_config,
6388: $line,'incorrectCODE',\%allcodes);
6389: return(1,$currentphase);
6390: }
1.221 albertel 6391: if (%allcodes && !exists($allcodes{$CODE})
6392: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 6393: &scantron_get_correction($r,$i,$scan_record,
6394: \%scantron_config,
1.194 albertel 6395: $line,'incorrectCODE',\%allcodes);
6396: return(1,$currentphase);
1.186 albertel 6397: }
1.214 albertel 6398: if (exists($usedCODEs{$CODE})
1.257 albertel 6399: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 6400: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 6401: &scantron_get_correction($r,$i,$scan_record,
6402: \%scantron_config,
1.194 albertel 6403: $line,'duplicateCODE',$usedCODEs{$CODE});
6404: return(1,$currentphase);
1.186 albertel 6405: }
1.194 albertel 6406: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 6407: }
1.157 albertel 6408: return (0,$currentphase+1);
6409: }
6410:
1.423 albertel 6411: =pod
6412:
6413: =item scantron_validate_doublebubble
6414:
1.424 albertel 6415: Validates all scanlines in the selected file to not have any
6416: bubble lines with multiple bubbles marked.
6417:
1.423 albertel 6418: =cut
6419:
1.157 albertel 6420: sub scantron_validate_doublebubble {
6421: my ($r,$currentphase) = @_;
6422: #get student info
6423: my $classlist=&Apache::loncoursedata::get_classlist();
6424: my %idmap=&username_to_idmap($classlist);
6425:
6426: #get scantron line setup
1.257 albertel 6427: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6428: my ($scanlines,$scan_data)=&scantron_getfile();
6429: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6430: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6431: if ($line=~/^[\s\cz]*$/) { next; }
6432: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6433: $scan_data);
6434: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
6435: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
6436: 'doublebubble',
6437: $$scan_record{'scantron.doubleerror'});
6438: return (1,$currentphase);
6439: }
6440: return (0,$currentphase+1);
6441: }
6442:
1.423 albertel 6443: =pod
6444:
6445: =item scantron_get_maxbubble
6446:
1.424 albertel 6447: Returns the maximum number of bubble lines that are expected to
6448: occur. Does this by walking the selected sequence rendering the
6449: resource and then checking &Apache::lonxml::get_problem_counter()
6450: for what the current value of the problem counter is.
6451:
6452: Caches the result to $env{'form.scantron_maxbubble'}
6453:
1.423 albertel 6454: =cut
6455:
1.330 albertel 6456: sub scantron_get_maxbubble {
1.257 albertel 6457: if (defined($env{'form.scantron_maxbubble'}) &&
6458: $env{'form.scantron_maxbubble'}) {
6459: return $env{'form.scantron_maxbubble'};
1.191 albertel 6460: }
1.330 albertel 6461:
1.191 albertel 6462: my $navmap=Apache::lonnavmaps::navmap->new();
6463: my (undef,undef,$sequence)=
1.257 albertel 6464: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 6465:
1.191 albertel 6466: my $map=$navmap->getResourceByUrl($sequence);
6467: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 6468:
6469: &Apache::lonxml::clear_problem_counter();
6470:
1.191 albertel 6471: foreach my $resource (@resources) {
1.330 albertel 6472: my $result=&Apache::lonnet::ssi($resource->src(),
6473: ('symb' => $resource->symb()));
1.191 albertel 6474: }
6475: &Apache::lonnet::delenv('scantron\.');
1.330 albertel 6476: $env{'form.scantron_maxbubble'} =
6477: &Apache::lonxml::get_problem_counter()-1;
6478:
1.257 albertel 6479: return $env{'form.scantron_maxbubble'};
1.191 albertel 6480: }
6481:
1.423 albertel 6482: =pod
6483:
6484: =item scantron_validate_missingbubbles
6485:
1.424 albertel 6486: Validates all scanlines in the selected file to not have any
6487: bubble lines with missing bubbles that haven't been verified as missing.
6488:
1.423 albertel 6489: =cut
6490:
1.157 albertel 6491: sub scantron_validate_missingbubbles {
6492: my ($r,$currentphase) = @_;
6493: #get student info
6494: my $classlist=&Apache::loncoursedata::get_classlist();
6495: my %idmap=&username_to_idmap($classlist);
6496:
6497: #get scantron line setup
1.257 albertel 6498: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6499: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 6500: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 6501: if (!$max_bubble) { $max_bubble=2**31; }
6502: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6503: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6504: if ($line=~/^[\s\cz]*$/) { next; }
6505: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6506: $scan_data);
6507: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
6508: my @to_correct;
6509: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
6510: if ($missing > $max_bubble) { next; }
6511: push(@to_correct,$missing);
6512: }
6513: if (@to_correct) {
6514: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6515: $line,'missingbubble',\@to_correct);
6516: return (1,$currentphase);
6517: }
6518:
6519: }
6520: return (0,$currentphase+1);
6521: }
6522:
1.423 albertel 6523: =pod
6524:
6525: =item scantron_process_students
6526:
6527: Routine that does the actual grading of the bubble sheet information.
6528:
6529: The parsed scanline hash is added to %env
6530:
6531: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
6532: foreach resource , with the form data of
6533:
6534: 'submitted' =>'scantron'
6535: 'grade_target' =>'grade',
6536: 'grade_username'=> username of student
6537: 'grade_domain' => domain of student
6538: 'grade_courseid'=> of course
6539: 'grade_symb' => symb of resource to grade
6540:
6541: This triggers a grading pass. The problem grading code takes care
6542: of converting the bubbled letter information (now in %env) into a
6543: valid submission.
6544:
6545: =cut
6546:
1.82 albertel 6547: sub scantron_process_students {
1.75 albertel 6548: my ($r) = @_;
1.257 albertel 6549: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 6550: my ($symb)=&get_symb($r);
1.81 albertel 6551: if (!$symb) {return '';}
1.324 albertel 6552: my $default_form_data=&defaultFormData($symb);
1.82 albertel 6553:
1.257 albertel 6554: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6555: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 6556: my $classlist=&Apache::loncoursedata::get_classlist();
6557: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 6558: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 6559: my $map=$navmap->getResourceByUrl($sequence);
6560: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 6561: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 6562: my $result= <<SCANTRONFORM;
1.81 albertel 6563: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
6564: <input type="hidden" name="command" value="scantron_configphase" />
6565: $default_form_data
6566: SCANTRONFORM
1.82 albertel 6567: $r->print($result);
6568:
6569: my @delayqueue;
1.140 albertel 6570: my %completedstudents;
6571:
1.200 albertel 6572: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 6573: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 6574: 'Scantron Progress',$count,
1.195 albertel 6575: 'inline',undef,'scantronupload');
1.140 albertel 6576: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
6577: 'Processing first student');
6578: my $start=&Time::HiRes::time();
1.158 albertel 6579: my $i=-1;
1.200 albertel 6580: my ($uname,$udom,$started);
1.157 albertel 6581: while ($i<$scanlines->{'count'}) {
6582: ($uname,$udom)=('','');
6583: $i++;
1.200 albertel 6584: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6585: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 6586: if ($started) {
6587: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
6588: 'last student');
6589: }
6590: $started=1;
1.157 albertel 6591: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6592: $scan_data);
6593: unless ($uname=&scantron_find_student($scan_record,$scan_data,
6594: \%idmap,$i)) {
6595: &scantron_add_delay(\@delayqueue,$line,
6596: 'Unable to find a student that matches',1);
6597: next;
6598: }
6599: if (exists $completedstudents{$uname}) {
6600: &scantron_add_delay(\@delayqueue,$line,
6601: 'Student '.$uname.' has multiple sheets',2);
6602: next;
6603: }
6604: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 6605:
6606: &Apache::lonxml::clear_problem_counter();
1.157 albertel 6607: &Apache::lonnet::appenv(%$scan_record);
1.376 albertel 6608:
6609: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
6610: &scantron_putfile($scanlines,$scan_data);
6611: }
1.161 albertel 6612:
6613: my $i=0;
1.83 albertel 6614: foreach my $resource (@resources) {
1.85 albertel 6615: $i++;
1.193 albertel 6616: my %form=('submitted' =>'scantron',
6617: 'grade_target' =>'grade',
6618: 'grade_username'=>$uname,
6619: 'grade_domain' =>$udom,
1.257 albertel 6620: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 6621: 'grade_symb' =>$resource->symb());
1.383 albertel 6622: if (exists($scan_record->{'scantron.CODE'})
6623: &&
6624: &Apache::lonnet::validCODE($scan_record->{'scantron.CODE'})) {
1.193 albertel 6625: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 6626: } else {
6627: $form{'CODE'}='';
1.193 albertel 6628: }
6629: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 6630: if ($result ne '') {
6631: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 6632: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 6633: }
1.213 albertel 6634: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 6635: }
1.140 albertel 6636: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 6637: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 6638: } continue {
1.330 albertel 6639: &Apache::lonxml::clear_problem_counter();
1.83 albertel 6640: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 6641: }
1.140 albertel 6642: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 6643: # my $lasttime = &Time::HiRes::time()-$start;
6644: # $r->print("<p>took $lasttime</p>");
1.140 albertel 6645:
1.200 albertel 6646: $r->print("</form>");
1.324 albertel 6647: $r->print(&show_grading_menu_form($symb));
1.157 albertel 6648: return '';
1.75 albertel 6649: }
1.157 albertel 6650:
1.423 albertel 6651: =pod
6652:
6653: =item scantron_upload_scantron_data
6654:
6655: Creates the screen for adding a new bubble sheet data file to a course.
6656:
6657: =cut
6658:
1.157 albertel 6659: sub scantron_upload_scantron_data {
6660: my ($r)=@_;
1.257 albertel 6661: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 6662: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 6663: 'domainid',
6664: 'coursename');
1.257 albertel 6665: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 6666: 'domainid');
1.324 albertel 6667: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.157 albertel 6668: $r->print(<<UPLOAD);
6669: <script type="text/javascript" language="javascript">
6670: function checkUpload(formname) {
6671: if (formname.upfile.value == "") {
6672: alert("Please use the browse button to select a file from your local directory.");
6673: return false;
6674: }
6675: formname.submit();
6676: }
6677: </script>
6678:
6679: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 6680: $default_form_data
1.181 albertel 6681: <table>
6682: <tr><td>$select_link </td></tr>
6683: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
6684: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
6685: <tr><td>Domain: </td><td>$domsel </td></tr>
6686: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
6687: </table>
1.157 albertel 6688: <input name='command' value='scantronupload_save' type='hidden' />
6689: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
6690: </form>
6691: UPLOAD
6692: return '';
6693: }
6694:
1.423 albertel 6695: =pod
6696:
6697: =item scantron_upload_scantron_data_save
6698:
6699: Adds a provided bubble information data file to the course if user
6700: has the correct privileges to do so.
6701:
6702: =cut
6703:
1.157 albertel 6704: sub scantron_upload_scantron_data_save {
6705: my($r)=@_;
1.324 albertel 6706: my ($symb)=&get_symb($r,1);
1.182 albertel 6707: my $doanotherupload=
6708: '<br /><form action="/adm/grades" method="post">'."\n".
6709: '<input type="hidden" name="command" value="scantronupload" />'."\n".
6710: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
6711: '</form>'."\n";
1.257 albertel 6712: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 6713: !&Apache::lonnet::allowed('usc',
1.257 albertel 6714: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 6715: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 6716: if ($symb) {
1.324 albertel 6717: $r->print(&show_grading_menu_form($symb));
1.182 albertel 6718: } else {
6719: $r->print($doanotherupload);
6720: }
1.162 albertel 6721: return '';
6722: }
1.257 albertel 6723: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 6724: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 6725: my $fname=$env{'form.upfile.filename'};
1.157 albertel 6726: #FIXME
6727: #copied from lonnet::userfileupload()
6728: #make that function able to target a specified course
6729: # Replace Windows backslashes by forward slashes
6730: $fname=~s/\\/\//g;
6731: # Get rid of everything but the actual filename
6732: $fname=~s/^.*\/([^\/]+)$/$1/;
6733: # Replace spaces by underscores
6734: $fname=~s/\s+/\_/g;
6735: # Replace all other weird characters by nothing
6736: $fname=~s/[^\w\.\-]//g;
6737: # See if there is anything left
6738: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 6739: my $uploadedfile=$fname;
1.157 albertel 6740: $fname='scantron_orig_'.$fname;
1.257 albertel 6741: if (length($env{'form.upfile'}) < 2) {
1.398 albertel 6742: $r->print("<span class=\"LC_error\">Error:</span> The file you attempted to upload, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename.");
1.183 albertel 6743: } else {
1.275 albertel 6744: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 6745: if ($result =~ m|^/uploaded/|) {
1.398 albertel 6746: $r->print("<span class=\"LC_success\">Success:</span> Successfully uploaded ".(length($env{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
1.210 albertel 6747: } else {
1.398 albertel 6748: $r->print("<span class=\"LC_error\">Error:</span> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>");
1.183 albertel 6749: }
6750: }
1.174 albertel 6751: if ($symb) {
1.209 ng 6752: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 6753: } else {
1.182 albertel 6754: $r->print($doanotherupload);
1.174 albertel 6755: }
1.157 albertel 6756: return '';
6757: }
6758:
1.423 albertel 6759: =pod
6760:
6761: =item valid_file
6762:
1.424 albertel 6763: Validates that the requested bubble data file exists in the course.
1.423 albertel 6764:
6765: =cut
6766:
1.202 albertel 6767: sub valid_file {
6768: my ($requested_file)=@_;
6769: foreach my $filename (sort(&scantron_filenames())) {
6770: if ($requested_file eq $filename) { return 1; }
6771: }
6772: return 0;
6773: }
6774:
1.423 albertel 6775: =pod
6776:
6777: =item scantron_download_scantron_data
6778:
6779: Shows a list of the three internal files (original, corrected,
6780: skipped) for a specific bubble sheet data file that exists in the
6781: course.
6782:
6783: =cut
6784:
1.202 albertel 6785: sub scantron_download_scantron_data {
6786: my ($r)=@_;
1.324 albertel 6787: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 6788: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6789: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6790: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 6791: if (! &valid_file($file)) {
6792: $r->print(<<ERROR);
6793: <p>
6794: The requested file name was invalid.
6795: </p>
6796: ERROR
1.324 albertel 6797: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 6798: return;
6799: }
6800: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
6801: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
6802: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
6803: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
6804: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
6805: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
6806: $r->print(<<DOWNLOAD);
6807: <p>
6808: <a href="$orig">Original</a> file as uploaded by the scantron office.
6809: </p>
6810: <p>
6811: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
6812: </p>
6813: <p>
6814: <a href="$skipped">Skipped</a>, a file of records that were skipped.
6815: </p>
6816: DOWNLOAD
1.324 albertel 6817: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 6818: return '';
6819: }
1.157 albertel 6820:
1.423 albertel 6821: =pod
6822:
6823: =back
6824:
6825: =cut
6826:
1.75 albertel 6827: #-------- end of section for handling grading scantron forms -------
6828: #
6829: #-------------------------------------------------------------------
6830:
1.72 ng 6831: #-------------------------- Menu interface -------------------------
6832: #
6833: #--- Show a Grading Menu button - Calls the next routine ---
6834: sub show_grading_menu_form {
1.324 albertel 6835: my ($symb)=@_;
1.125 ng 6836: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 6837: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 6838: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 6839: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
6840: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
6841: '</form>'."\n";
6842: return $result;
6843: }
6844:
1.77 ng 6845: # -- Retrieve choices for grading form
6846: sub savedState {
6847: my %savedState = ();
1.257 albertel 6848: if ($env{'form.saveState'}) {
6849: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 6850: my ($key,$value) = split(/=/,$_,2);
6851: $savedState{$key} = $value;
6852: }
6853: }
6854: return \%savedState;
6855: }
1.76 ng 6856:
1.72 ng 6857: #--- Displays the main menu page -------
6858: sub gradingmenu {
6859: my ($request) = @_;
1.324 albertel 6860: my ($symb)=&get_symb($request);
1.72 ng 6861: if (!$symb) {return '';}
1.76 ng 6862: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 6863:
6864: $request->print(<<GRADINGMENUJS);
6865: <script type="text/javascript" language="javascript">
1.116 ng 6866: function checkChoice(formname,val,cmdx) {
6867: if (val <= 2) {
6868: var cmd = radioSelection(formname.radioChoice);
1.118 ng 6869: var cmdsave = cmd;
1.116 ng 6870: } else {
6871: cmd = cmdx;
1.118 ng 6872: cmdsave = 'submission';
1.116 ng 6873: }
6874: formname.command.value = cmd;
1.118 ng 6875: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 6876: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 6877: if (val < 5) formname.submit();
6878: if (val == 5) {
1.72 ng 6879: if (!checkReceiptNo(formname,'notOK')) { return false;}
6880: formname.submit();
6881: }
1.238 albertel 6882: if (val < 7) formname.submit();
1.72 ng 6883: }
6884:
6885: function checkReceiptNo(formname,nospace) {
6886: var receiptNo = formname.receipt.value;
6887: var checkOpt = false;
6888: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
6889: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
6890: if (checkOpt) {
6891: alert("Please enter a receipt number given by a student in the receipt box.");
6892: formname.receipt.value = "";
6893: formname.receipt.focus();
6894: return false;
6895: }
6896: return true;
6897: }
6898: </script>
6899: GRADINGMENUJS
1.118 ng 6900: &commonJSfunctions($request);
1.398 albertel 6901: my $result='<h3> <span class="LC_info">Manual Grading/View Submission</span></h3>';
1.324 albertel 6902: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.118 ng 6903: $result.=$table;
1.76 ng 6904: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 6905: my $savedState = &savedState();
1.118 ng 6906: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 6907: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 6908: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 6909: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 6910:
6911: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 6912: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 6913: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
6914: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 6915: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 6916: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 6917: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 6918: '<input type="hidden" name="showgrading" value="yes" />'."\n";
6919:
1.326 albertel 6920: $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
6921: '<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 6922: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 6923: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
6924:
1.326 albertel 6925: $result.='<table width="100%" border="0">';
1.116 ng 6926: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 6927: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 6928: if (ref($sections)) {
1.155 albertel 6929: foreach (sort (@$sections)) {
6930: $result.='<option value="'.$_.'" '.
1.401 albertel 6931: ($saveSec eq $_ ? 'selected="selected"':'').'>'.$_.'</option>'."\n";
1.155 albertel 6932: }
1.116 ng 6933: }
1.401 albertel 6934: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.116 ng 6935:
1.401 albertel 6936: $result.=&mt('Student Status').':'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 6937:
1.116 ng 6938: $result.='</td></tr>';
6939:
1.288 albertel 6940: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 6941: '<input type="radio" name="radioChoice" value="submission" '.
1.401 albertel 6942: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 6943: '</label> <select name="submitonly">'.
1.145 albertel 6944: '<option value="yes" '.
1.401 albertel 6945: ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>'.
1.301 albertel 6946: '<option value="queued" '.
1.401 albertel 6947: ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>'.
1.145 albertel 6948: '<option value="graded" '.
1.401 albertel 6949: ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 6950: '<option value="incorrect" '.
1.401 albertel 6951: ($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 6952: '<option value="all" '.
1.401 albertel 6953: ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 6954:
1.116 ng 6955: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 6956: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.401 albertel 6957: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
1.288 albertel 6958: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 6959:
1.118 ng 6960: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 6961: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.401 albertel 6962: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
1.288 albertel 6963: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 6964:
1.116 ng 6965: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 6966: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 6967: '</td></tr></table>'."\n";
6968:
6969: $result.='</td><td valign="top">';
6970:
1.326 albertel 6971: $result.='<table width="100%" border="0">';
1.116 ng 6972: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 6973: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
6974: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 6975:
1.404 www 6976: $result.='<tr bgcolor="#ffffe6"><td>'.
6977: '<input type="button" onClick="javascript:checkChoice(this.form,\'6\',\'processclicker\');" value="'.&mt('Process').'" />'.
6978: ' '.&mt('clicker file').' </td></tr>'."\n";
1.400 www 6979:
1.75 albertel 6980: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 6981: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 6982: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 6983:
1.257 albertel 6984: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 6985: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 6986: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
6987: ' '.&mt('receipt').': '.
1.257 albertel 6988: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.326 albertel 6989: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
1.72 ng 6990: '</td></tr>'."\n";
6991: }
1.238 albertel 6992: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6993: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
6994: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 6995: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6996: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
6997: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 6998:
1.401 albertel 6999: $result.='</table>'."\n".
1.72 ng 7000: '</td></tr></table>'."\n".
1.401 albertel 7001: '</td></tr></table></form>'."\n";
1.44 ng 7002: return $result;
1.2 albertel 7003: }
7004:
1.285 albertel 7005: sub reset_perm {
7006: undef(%perm);
7007: }
7008:
7009: sub init_perm {
7010: &reset_perm();
1.300 albertel 7011: foreach my $test_perm ('vgr','mgr','opa') {
7012:
7013: my $scope = $env{'request.course.id'};
7014: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
7015:
7016: $scope .= '/'.$env{'request.course.sec'};
7017: if ( $perm{$test_perm}=
7018: &Apache::lonnet::allowed($test_perm,$scope)) {
7019: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
7020: } else {
7021: delete($perm{$test_perm});
7022: }
1.285 albertel 7023: }
7024: }
7025: }
7026:
1.400 www 7027: sub gather_clicker_ids {
1.408 albertel 7028: my %clicker_ids;
1.400 www 7029:
7030: my $classlist = &Apache::loncoursedata::get_classlist();
7031:
7032: # Set up a couple variables.
1.407 albertel 7033: my $username_idx = &Apache::loncoursedata::CL_SNAME();
7034: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.400 www 7035:
1.407 albertel 7036: foreach my $student (keys(%$classlist)) {
1.400 www 7037:
1.407 albertel 7038: my $username = $classlist->{$student}->[$username_idx];
7039: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 7040: my $clickers =
1.408 albertel 7041: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 7042: foreach my $id (split(/\,/,$clickers)) {
1.414 www 7043: $id=~s/^[\#0]+//;
1.421 www 7044: $id=~s/[\-\:]//g;
1.407 albertel 7045: if (exists($clicker_ids{$id})) {
1.408 albertel 7046: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 7047: } else {
1.408 albertel 7048: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 7049: }
7050: }
7051: }
1.407 albertel 7052: return %clicker_ids;
1.400 www 7053: }
7054:
1.402 www 7055: sub gather_adv_clicker_ids {
1.408 albertel 7056: my %clicker_ids;
1.402 www 7057: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
7058: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7059: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 7060: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 7061: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
7062: my ($puname,$pudom)=split(/\:/,$person);
7063: my $clickers =
1.408 albertel 7064: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 7065: foreach my $id (split(/\,/,$clickers)) {
1.414 www 7066: $id=~s/^[\#0]+//;
1.421 www 7067: $id=~s/[\-\:]//g;
1.408 albertel 7068: if (exists($clicker_ids{$id})) {
7069: $clicker_ids{$id}.=','.$puname.':'.$pudom;
7070: } else {
7071: $clicker_ids{$id}=$puname.':'.$pudom;
7072: }
1.405 www 7073: }
1.402 www 7074: }
7075: }
1.407 albertel 7076: return %clicker_ids;
1.402 www 7077: }
7078:
1.413 www 7079: sub clicker_grading_parameters {
7080: return ('gradingmechanism' => 'scalar',
7081: 'upfiletype' => 'scalar',
7082: 'specificid' => 'scalar',
7083: 'pcorrect' => 'scalar',
7084: 'pincorrect' => 'scalar');
7085: }
7086:
1.400 www 7087: sub process_clicker {
7088: my ($r)=@_;
7089: my ($symb)=&get_symb($r);
7090: if (!$symb) {return '';}
7091: my $result=&checkforfile_js();
7092: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
7093: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
7094: $result.=$table;
7095: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
7096: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
7097: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource').
7098: '.</b></td></tr>'."\n";
7099: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 7100: # Attempt to restore parameters from last session, set defaults if not present
7101: my %Saveable_Parameters=&clicker_grading_parameters();
7102: &Apache::loncommon::restore_course_settings('grades_clicker',
7103: \%Saveable_Parameters);
7104: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
7105: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
7106: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
7107: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
7108:
7109: my %checked;
7110: foreach my $gradingmechanism ('attendance','personnel','specific') {
7111: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
7112: $checked{$gradingmechanism}="checked='checked'";
7113: }
7114: }
7115:
1.400 www 7116: my $upload=&mt("Upload File");
7117: my $type=&mt("Type");
1.402 www 7118: my $attendance=&mt("Award points just for participation");
7119: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 7120: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.402 www 7121: my $pcorrect=&mt("Percentage points for correct solution");
7122: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 7123: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 7124: ('iclicker' => 'i>clicker',
7125: 'interwrite' => 'interwrite PRS'));
1.418 albertel 7126: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 7127: $result.=<<ENDUPFORM;
1.402 www 7128: <script type="text/javascript">
7129: function sanitycheck() {
7130: // Accept only integer percentages
7131: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
7132: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
7133: // Find out grading choice
7134: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
7135: if (document.forms.gradesupload.gradingmechanism[i].checked) {
7136: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
7137: }
7138: }
7139: // By default, new choice equals user selection
7140: newgradingchoice=gradingchoice;
7141: // Not good to give more points for false answers than correct ones
7142: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
7143: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
7144: }
7145: // If new choice is attendance only, and old choice was correctness-based, restore defaults
7146: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
7147: document.forms.gradesupload.pcorrect.value=100;
7148: document.forms.gradesupload.pincorrect.value=100;
7149: }
7150: // If the values are different, cannot be attendance only
7151: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
7152: (gradingchoice=='attendance')) {
7153: newgradingchoice='personnel';
7154: }
7155: // Change grading choice to new one
7156: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
7157: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
7158: document.forms.gradesupload.gradingmechanism[i].checked=true;
7159: } else {
7160: document.forms.gradesupload.gradingmechanism[i].checked=false;
7161: }
7162: }
7163: // Remember the old state
7164: document.forms.gradesupload.waschecked.value=newgradingchoice;
7165: }
7166: </script>
1.400 www 7167: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
7168: <input type="hidden" name="symb" value="$symb" />
7169: <input type="hidden" name="command" value="processclickerfile" />
7170: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
7171: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
7172: <input type="file" name="upfile" size="50" />
7173: <br /><label>$type: $selectform</label>
1.413 www 7174: <br /><label>$attendance: <input type="radio" name="gradingmechanism" value="attendance" $checked{'attendance'} onClick="sanitycheck()" /></label>
7175: <br /><label>$personnel: <input type="radio" name="gradingmechanism" value="personnel" $checked{'personnel'} onClick="sanitycheck()" /></label>
7176: <br /><label>$specific: <input type="radio" name="gradingmechanism" value="specific" $checked{'specific'} onClick="sanitycheck()" /></label>
1.414 www 7177: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.413 www 7178: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
7179: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onChange="sanitycheck()" /></label>
7180: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onChange="sanitycheck()" /></label>
1.400 www 7181: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
7182: </form>
7183: ENDUPFORM
7184: $result.='</td></tr></table>'."\n".
7185: '</td></tr></table><br /><br />'."\n";
7186: $result.=&show_grading_menu_form($symb);
7187: return $result;
7188: }
7189:
7190: sub process_clicker_file {
7191: my ($r)=@_;
7192: my ($symb)=&get_symb($r);
7193: if (!$symb) {return '';}
1.413 www 7194:
7195: my %Saveable_Parameters=&clicker_grading_parameters();
7196: &Apache::loncommon::store_course_settings('grades_clicker',
7197: \%Saveable_Parameters);
7198:
1.400 www 7199: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 7200: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 7201: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
7202: return $result.&show_grading_menu_form($symb);
1.404 www 7203: }
1.407 albertel 7204: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 7205: my %correct_ids;
1.404 www 7206: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 7207: %correct_ids=&gather_adv_clicker_ids();
1.404 www 7208: }
7209: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 7210: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
7211: $correct_id=~tr/a-z/A-Z/;
7212: $correct_id=~s/\s//gs;
7213: $correct_id=~s/^[\#0]+//;
1.421 www 7214: $correct_id=~s/[\-\:]//g;
1.414 www 7215: if ($correct_id) {
7216: $correct_ids{$correct_id}='specified';
7217: }
7218: }
1.400 www 7219: }
1.404 www 7220: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 7221: $result.=&mt('Score based on attendance only');
1.404 www 7222: } else {
1.408 albertel 7223: my $number=0;
1.411 www 7224: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 7225: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 7226: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 7227: if ($correct_ids{$id} eq 'specified') {
7228: $result.=&mt('specified');
7229: } else {
7230: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
7231: $result.=&Apache::loncommon::plainname($uname,$udom);
7232: }
7233: $number++;
7234: }
1.411 www 7235: $result.="</p>\n";
1.408 albertel 7236: if ($number==0) {
7237: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
7238: return $result.&show_grading_menu_form($symb);
7239: }
1.404 www 7240: }
1.405 www 7241: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 7242: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
7243: '<span class="LC_error">',
7244: '</span>',
7245: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 7246: return $result.&show_grading_menu_form($symb);
7247: }
1.410 www 7248:
7249: # Were able to get all the info needed, now analyze the file
7250:
1.411 www 7251: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 7252: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 7253: my $heading=&mt('Scanning clicker file');
7254: $result.=(<<ENDHEADER);
7255: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
7256: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
7257: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
7258: <form method="post" action="/adm/grades" name="clickeranalysis">
7259: <input type="hidden" name="symb" value="$symb" />
7260: <input type="hidden" name="command" value="assignclickergrades" />
7261: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
7262: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 7263: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
7264: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
7265: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 7266: ENDHEADER
1.408 albertel 7267: my %responses;
7268: my @questiontitles;
1.405 www 7269: my $errormsg='';
7270: my $number=0;
7271: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 7272: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 7273: }
1.419 www 7274: if ($env{'form.upfiletype'} eq 'interwrite') {
7275: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
7276: }
1.411 www 7277: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
7278: '<input type="hidden" name="number" value="'.$number.'" />'.
7279: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
7280: $env{'form.pcorrect'},$env{'form.pincorrect'}).
7281: '<br />';
1.414 www 7282: # Remember Question Titles
7283: # FIXME: Possibly need delimiter other than ":"
7284: for (my $i=0;$i<$number;$i++) {
7285: $result.='<input type="hidden" name="question:'.$i.'" value="'.
7286: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
7287: }
1.411 www 7288: my $correct_count=0;
7289: my $student_count=0;
7290: my $unknown_count=0;
1.414 www 7291: # Match answers with usernames
7292: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 7293: foreach my $id (keys(%responses)) {
1.410 www 7294: if ($correct_ids{$id}) {
1.414 www 7295: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 7296: $correct_count++;
1.410 www 7297: } elsif ($clicker_ids{$id}) {
7298: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 7299: $student_count++;
1.410 www 7300: } else {
1.411 www 7301: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
7302: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
7303: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
7304: "\n".&mt("Domain").": ".
7305: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
7306: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
7307: $unknown_count++;
1.410 www 7308: }
1.405 www 7309: }
1.412 www 7310: $result.='<hr />'.
7311: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
7312: if ($env{'form.gradingmechanism'} ne 'attendance') {
7313: if ($correct_count==0) {
7314: $errormsg.="Found no correct answers answers for grading!";
7315: } elsif ($correct_count>1) {
1.414 www 7316: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 7317: }
7318: }
7319: if ($errormsg) {
7320: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
7321: } else {
7322: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
7323: }
7324: $result.='</form></td></tr></table>'."\n".
1.410 www 7325: '</td></tr></table><br /><br />'."\n";
1.404 www 7326: return $result.&show_grading_menu_form($symb);
1.400 www 7327: }
7328:
1.405 www 7329: sub iclicker_eval {
1.406 www 7330: my ($questiontitles,$responses)=@_;
1.405 www 7331: my $number=0;
7332: my $errormsg='';
7333: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 7334: my %components=&Apache::loncommon::record_sep($line);
7335: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 7336: if ($entries[0] eq 'Question') {
7337: for (my $i=3;$i<$#entries;$i+=6) {
7338: $$questiontitles[$number]=$entries[$i];
7339: $number++;
7340: }
7341: }
7342: if ($entries[0]=~/^\#/) {
7343: my $id=$entries[0];
7344: my @idresponses;
7345: $id=~s/^[\#0]+//;
7346: for (my $i=0;$i<$number;$i++) {
7347: my $idx=3+$i*6;
7348: push(@idresponses,$entries[$idx]);
7349: }
7350: $$responses{$id}=join(',',@idresponses);
7351: }
1.405 www 7352: }
7353: return ($errormsg,$number);
7354: }
7355:
1.419 www 7356: sub interwrite_eval {
7357: my ($questiontitles,$responses)=@_;
7358: my $number=0;
7359: my $errormsg='';
1.420 www 7360: my $skipline=1;
7361: my $questionnumber=0;
7362: my %idresponses=();
1.419 www 7363: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
7364: my %components=&Apache::loncommon::record_sep($line);
7365: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 7366: if ($entries[1] eq 'Time') { $skipline=0; next; }
7367: if ($entries[1] eq 'Response') { $skipline=1; }
7368: next if $skipline;
7369: if ($entries[0]!=$questionnumber) {
7370: $questionnumber=$entries[0];
7371: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
7372: $number++;
1.419 www 7373: }
1.420 www 7374: my $id=$entries[4];
7375: $id=~s/^[\#0]+//;
1.421 www 7376: $id=~s/^v\d*\://i;
7377: $id=~s/[\-\:]//g;
1.420 www 7378: $idresponses{$id}[$number]=$entries[6];
7379: }
7380: foreach my $id (keys %idresponses) {
7381: $$responses{$id}=join(',',@{$idresponses{$id}});
7382: $$responses{$id}=~s/^\s*\,//;
1.419 www 7383: }
7384: return ($errormsg,$number);
7385: }
7386:
1.414 www 7387: sub assign_clicker_grades {
7388: my ($r)=@_;
7389: my ($symb)=&get_symb($r);
7390: if (!$symb) {return '';}
1.416 www 7391: # See which part we are saving to
7392: my ($partlist,$handgrade,$responseType) = &response_type($symb);
7393: # FIXME: This should probably look for the first handgradeable part
7394: my $part=$$partlist[0];
7395: # Start screen output
1.414 www 7396: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 7397:
1.414 www 7398: my $heading=&mt('Assigning grades based on clicker file');
7399: $result.=(<<ENDHEADER);
7400: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
7401: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
7402: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
7403: ENDHEADER
7404: # Get correct result
7405: # FIXME: Possibly need delimiter other than ":"
7406: my @correct=();
1.415 www 7407: my $gradingmechanism=$env{'form.gradingmechanism'};
7408: my $number=$env{'form.number'};
7409: if ($gradingmechanism ne 'attendance') {
1.414 www 7410: foreach my $key (keys(%env)) {
7411: if ($key=~/^form\.correct\:/) {
7412: my @input=split(/\,/,$env{$key});
7413: for (my $i=0;$i<=$#input;$i++) {
7414: if (($correct[$i]) && ($input[$i]) &&
7415: ($correct[$i] ne $input[$i])) {
7416: $result.='<br /><span class="LC_warning">'.
7417: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
7418: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
7419: } elsif ($input[$i]) {
7420: $correct[$i]=$input[$i];
7421: }
7422: }
7423: }
7424: }
1.415 www 7425: for (my $i=0;$i<$number;$i++) {
1.414 www 7426: if (!$correct[$i]) {
7427: $result.='<br /><span class="LC_error">'.
7428: &mt('No correct result given for question "[_1]"!',
7429: $env{'form.question:'.$i}).'</span>';
7430: }
7431: }
7432: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
7433: }
7434: # Start grading
1.415 www 7435: my $pcorrect=$env{'form.pcorrect'};
7436: my $pincorrect=$env{'form.pincorrect'};
1.416 www 7437: my $storecount=0;
1.415 www 7438: foreach my $key (keys(%env)) {
1.420 www 7439: my $user='';
1.415 www 7440: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 7441: $user=$1;
7442: }
7443: if ($key=~/^form\.unknown\:(.*)$/) {
7444: my $id=$1;
7445: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
7446: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
7447: }
7448: }
7449: if ($user) {
1.415 www 7450: my @answer=split(/\,/,$env{$key});
7451: my $sum=0;
7452: for (my $i=0;$i<$number;$i++) {
7453: if ($answer[$i]) {
7454: if ($gradingmechanism eq 'attendance') {
7455: $sum+=$pcorrect;
7456: } else {
7457: if ($answer[$i] eq $correct[$i]) {
7458: $sum+=$pcorrect;
7459: } else {
7460: $sum+=$pincorrect;
7461: }
7462: }
7463: }
7464: }
1.416 www 7465: my $ave=$sum/(100*$number);
7466: # Store
7467: my ($username,$domain)=split(/\:/,$user);
7468: my %grades=();
7469: $grades{"resource.$part.solved"}='correct_by_override';
7470: $grades{"resource.$part.awarded"}=$ave;
7471: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
7472: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
7473: $env{'request.course.id'},
7474: $domain,$username);
7475: if ($returncode ne 'ok') {
7476: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
7477: } else {
7478: $storecount++;
7479: }
1.415 www 7480: }
7481: }
7482: # We are done
1.416 www 7483: $result.='<br />'.&mt('Successfully stored grades for [_1] student(s).',$storecount).
7484: '</td></tr></table>'."\n".
1.414 www 7485: '</td></tr></table><br /><br />'."\n";
7486: return $result.&show_grading_menu_form($symb);
7487: }
7488:
1.1 albertel 7489: sub handler {
1.41 ng 7490: my $request=$_[0];
1.102 albertel 7491:
1.285 albertel 7492: &reset_perm();
1.257 albertel 7493: if ($env{'browser.mathml'}) {
1.141 www 7494: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 7495: } else {
1.141 www 7496: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 7497: }
7498: $request->send_http_header;
1.44 ng 7499: return '' if $request->header_only;
1.41 ng 7500: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 7501: my $symb=&get_symb($request,1);
1.160 albertel 7502: my @commands=&Apache::loncommon::get_env_multiple('form.command');
7503: my $command=$commands[0];
7504: if ($#commands > 0) {
7505: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
7506: }
1.353 albertel 7507: $request->print(&Apache::loncommon::start_page('Grading'));
1.324 albertel 7508: if ($symb eq '' && $command eq '') {
1.257 albertel 7509: if ($env{'user.adv'}) {
7510: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
7511: ($env{'form.codethree'})) {
7512: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
7513: $env{'form.codethree'};
1.41 ng 7514: my ($tsymb,$tuname,$tudom,$tcrsid)=
7515: &Apache::lonnet::checkin($token);
7516: if ($tsymb) {
1.137 albertel 7517: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 7518: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 7519: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
7520: ('grade_username' => $tuname,
7521: 'grade_domain' => $tudom,
7522: 'grade_courseid' => $tcrsid,
7523: 'grade_symb' => $tsymb)));
1.41 ng 7524: } else {
1.45 ng 7525: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 7526: }
1.41 ng 7527: } else {
1.45 ng 7528: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 7529: }
1.14 www 7530: } else {
1.41 ng 7531: $request->print(&Apache::lonxml::tokeninputfield());
7532: }
7533: }
7534: } else {
1.285 albertel 7535: &init_perm();
1.104 albertel 7536: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 7537: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 7538: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 7539: &pickStudentPage($request);
1.103 albertel 7540: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 7541: &displayPage($request);
1.104 albertel 7542: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 7543: &updateGradeByPage($request);
1.104 albertel 7544: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 7545: &processGroup($request);
1.104 albertel 7546: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 7547: $request->print(&gradingmenu($request));
1.104 albertel 7548: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 7549: $request->print(&viewgrades($request));
1.104 albertel 7550: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 7551: $request->print(&processHandGrade($request));
1.106 albertel 7552: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 7553: $request->print(&editgrades($request));
1.106 albertel 7554: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 7555: $request->print(&verifyreceipt($request));
1.400 www 7556: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
7557: $request->print(&process_clicker($request));
7558: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
7559: $request->print(&process_clicker_file($request));
1.414 www 7560: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
7561: $request->print(&assign_clicker_grades($request));
1.106 albertel 7562: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 7563: $request->print(&upcsvScores_form($request));
1.106 albertel 7564: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 7565: $request->print(&csvupload($request));
1.106 albertel 7566: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 7567: $request->print(&csvuploadmap($request));
1.246 albertel 7568: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 7569: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 7570: $request->print(&csvuploadoptions($request));
1.41 ng 7571: } else {
1.257 albertel 7572: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
7573: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 7574: } else {
1.257 albertel 7575: $env{'form.upfile_associate'} = 'forward';
1.41 ng 7576: }
7577: $request->print(&csvuploadmap($request));
7578: }
1.246 albertel 7579: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
7580: $request->print(&csvuploadassign($request));
1.106 albertel 7581: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 7582: $request->print(&scantron_selectphase($request));
1.203 albertel 7583: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
7584: $request->print(&scantron_do_warning($request));
1.142 albertel 7585: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
7586: $request->print(&scantron_validate_file($request));
1.106 albertel 7587: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 7588: $request->print(&scantron_process_students($request));
1.157 albertel 7589: } elsif ($command eq 'scantronupload' &&
1.257 albertel 7590: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
7591: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 7592: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 7593: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 7594: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
7595: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 7596: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 7597: } elsif ($command eq 'scantron_download' &&
1.257 albertel 7598: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 7599: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 7600: } elsif ($command) {
1.157 albertel 7601: $request->print("Access Denied ($command)");
1.26 albertel 7602: }
1.2 albertel 7603: }
1.353 albertel 7604: $request->print(&Apache::loncommon::end_page());
1.44 ng 7605: return '';
7606: }
7607:
1.1 albertel 7608: 1;
7609:
1.13 albertel 7610: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>