Annotation of loncom/homework/grades.pm, revision 1.349
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.349 ! albertel 4: # $Id: grades.pm,v 1.348 2006/04/09 20:53:27 bowersj2 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.38 ng 39: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 40: use Apache::Constants qw(:common);
1.167 sakharuk 41: use Apache::lonlocal;
1.170 albertel 42: use String::Similarity;
1.315 bowersj2 43: use POSIX qw(floor);
1.87 www 44:
45: my %oldessays=();
1.103 albertel 46: my %perm=();
1.1 albertel 47:
1.68 ng 48: # ----- These first few routines are general use routines.----
1.44 ng 49: #
1.146 albertel 50: # --- Retrieve the parts from the metadata file.---
1.44 ng 51: sub getpartlist {
1.324 albertel 52: my ($symb) = @_;
53: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.146 albertel 54: my $partorder = &Apache::lonnet::metadata($url, 'partorder');
55: my @parts;
56: if ($partorder) {
57: for my $part (split (/,/,$partorder)) {
58: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
59: push(@parts, $part);
60: }
61: }
62: } else {
63: my $metadata = &Apache::lonnet::metadata($url, 'packages');
64: foreach (split(/\,/,$metadata)) {
65: if ($_ =~ /^part_(.*)$/) {
66: if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
67: push(@parts, $1);
68: }
69: }
1.41 ng 70: }
1.16 albertel 71: }
1.146 albertel 72: my @stores;
73: foreach my $part (@parts) {
74: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
75: foreach my $key (@metakeys) {
76: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
77: }
78: }
79: return @stores;
1.2 albertel 80: }
81:
1.44 ng 82: # --- Get the symbolic name of a problem and the url
1.324 albertel 83: sub get_symb {
1.173 albertel 84: my ($request,$silent) = @_;
1.257 albertel 85: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
86: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 87: if ($symb eq '') {
88: if (!$silent) {
89: $request->print("Unable to handle ambiguous references:$url:.");
90: return ();
91: }
92: }
1.324 albertel 93: return ($symb);
1.32 ng 94: }
95:
1.129 ng 96: #--- Format fullname, username:domain if different for display
97: #--- Use anywhere where the student names are listed
98: sub nameUserString {
99: my ($type,$fullname,$uname,$udom) = @_;
100: if ($type eq 'header') {
1.250 albertel 101: return '<b> Fullname </b><font color="#999999">(Username)</font>';
1.129 ng 102: } else {
103: return ' '.$fullname.'<font color="#999999"> ('.$uname.
1.257 albertel 104: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
1.129 ng 105: }
106: }
107:
1.44 ng 108: #--- Get the partlist and the response type for a given problem. ---
109: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 110: sub response_type {
1.324 albertel 111: my ($symb) = shift;
112: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 113: my $allkeys = &Apache::lonnet::metadata($url,'keys');
1.154 albertel 114: my %vPart;
115: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
116: $vPart{$partid}=1;
117: }
1.41 ng 118: my %seen = ();
1.147 albertel 119: my (@partlist,%handgrade,%responseType);
1.41 ng 120: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.335 albertel 121: if (/^\w+response_.*/ || /^Task_/) {
1.41 ng 122: my ($responsetype,$part) = split(/_/,$_,2);
123: my ($partid,$respid) = split(/_/,$part);
1.335 albertel 124: if ($responsetype eq 'Task') { $respid='0'; }
1.146 albertel 125: if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
126: next;
127: }
1.154 albertel 128: if (%vPart && !exists($vPart{$partid})) {
129: next;
130: }
1.118 ng 131: $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
1.127 ng 132: my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
1.147 albertel 133: $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no');
134: if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
135: $responseType{$partid}->{$respid}=$responsetype;
1.41 ng 136: next if ($seen{$partid} > 0);
137: $seen{$partid}++;
138: push @partlist,$partid;
139: }
140: }
1.324 albertel 141: return (\@partlist,\%handgrade,\%responseType);
1.39 ng 142: }
143:
1.207 albertel 144: sub get_display_part {
1.324 albertel 145: my ($partID,$symb)=@_;
1.207 albertel 146: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
147: if (defined($display) and $display ne '') {
148: $display.= " (<font color=\"#999900\">id $partID</font>)";
149: } else {
150: $display=$partID;
151: }
152: return $display;
153: }
1.269 raeburn 154:
1.118 ng 155: #--- Show resource title
156: #--- and parts and response type
157: sub showResourceInfo {
1.324 albertel 158: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 159: my $col=3;
160: if ($checkboxes) { $col=4; }
1.118 ng 161: my $result ='<table border="0">'.
1.167 sakharuk 162: '<tr><td colspan="'.$col.'"><font size="+1"><b>'.&mt('Current Resource').': </b>'.
1.154 albertel 163: $probTitle.'</font></td></tr>'."\n";
1.324 albertel 164: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.126 ng 165: my %resptype = ();
1.122 ng 166: my $hdgrade='no';
1.154 albertel 167: my %partsseen;
1.147 albertel 168: for my $part_resID (sort keys(%$handgrade)) {
169: my $handgrade=$$handgrade{$part_resID};
170: my ($partID,$resID) = split(/_/,$part_resID);
171: my $responsetype = $responseType->{$partID}->{$resID};
1.118 ng 172: $hdgrade = $handgrade if ($handgrade eq 'yes');
1.154 albertel 173: $result.='<tr>';
174: if ($checkboxes) {
175: if (exists($partsseen{$partID})) {
176: $result.="<td> </td>";
177: } else {
178: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='on' /></td>";
179: }
180: $partsseen{$partID}=1;
181: }
1.324 albertel 182: my $display_part=&get_display_part($partID,$symb);
1.207 albertel 183: $result.='<td><b>Part: </b>'.$display_part.' <font color="#999999">'.
1.147 albertel 184: $resID.'</font></td>'.
1.118 ng 185: '<td><b>Type: </b>'.$responsetype.'</td></tr>';
186: # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
187: }
188: $result.='</table>'."\n";
1.147 albertel 189: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 190: }
191:
1.148 albertel 192:
193: sub get_order {
194: my ($partid,$respid,$symb,$uname,$udom)=@_;
195: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
196: $url=&Apache::lonnet::clutter($url);
197: my $subresult=&Apache::lonnet::ssi($url,
198: ('grade_target' => 'analyze'),
199: ('grade_domain' => $udom),
200: ('grade_symb' => $symb),
201: ('grade_courseid' =>
1.257 albertel 202: $env{'request.course.id'}),
1.148 albertel 203: ('grade_username' => $uname));
1.149 albertel 204: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148 albertel 205: my %analyze=&Apache::lonnet::str2hash($subresult);
206: return ($analyze{"$partid.$respid.shown"});
207: }
1.118 ng 208: #--- Clean response type for display
1.335 albertel 209: #--- Currently filters option/rank/radiobutton/match/essay/Task
210: # response types only.
1.118 ng 211: sub cleanRecord {
1.336 albertel 212: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
213: $uname,$udom) = @_;
1.148 albertel 214: my $grayFont = '<font color="#999999">';
215: if ($response =~ /^(option|rank)$/) {
216: my %answer=&Apache::lonnet::str2hash($answer);
217: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
218: my ($toprow,$bottomrow);
219: foreach my $foil (@$order) {
220: if ($grading{$foil} == 1) {
221: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
222: } else {
223: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
224: }
225: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
226: }
227: return '<blockquote><table border="1">'.
228: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
229: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
230: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
231: } elsif ($response eq 'match') {
232: my %answer=&Apache::lonnet::str2hash($answer);
233: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
234: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
235: my ($toprow,$middlerow,$bottomrow);
236: foreach my $foil (@$order) {
237: my $item=shift(@items);
238: if ($grading{$foil} == 1) {
239: $toprow.='<td><b>'.$item.' </b></td>';
240: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </font></b></td>';
241: } else {
242: $toprow.='<td><i>'.$item.' </i></td>';
243: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </font></i></td>';
244: }
245: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
1.118 ng 246: }
1.126 ng 247: return '<blockquote><table border="1">'.
1.148 albertel 248: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
249: '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
250: $middlerow.'</tr>'.
251: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
252: $bottomrow.'</tr>'.'</table></blockquote>';
253: } elsif ($response eq 'radiobutton') {
254: my %answer=&Apache::lonnet::str2hash($answer);
255: my ($toprow,$bottomrow);
256: my $correct=($order->[0])+1;
257: for (my $i=1;$i<=$#$order;$i++) {
258: my $foil=$order->[$i];
259: if (exists($answer{$foil})) {
260: if ($i == $correct) {
261: $toprow.='<td><b>true</b></td>';
262: } else {
263: $toprow.='<td><i>true</i></td>';
264: }
265: } else {
266: $toprow.='<td>false</td>';
267: }
268: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
269: }
270: return '<blockquote><table border="1">'.
271: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
272: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
273: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
274: } elsif ($response eq 'essay') {
1.257 albertel 275: if (! exists ($env{'form.'.$symb})) {
1.122 ng 276: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 277: $env{'course.'.$env{'request.course.id'}.'.domain'},
278: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 279:
1.257 albertel 280: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
281: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
282: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
283: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
284: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
285: $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 286: }
1.166 albertel 287: $answer =~ s-\n-<br />-g;
288: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 289: } elsif ( $response eq 'organic') {
290: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
291: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
292: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
293: return $result;
1.335 albertel 294: } elsif ( $response eq 'Task') {
295: if ( $answer eq 'SUBMITTED') {
296: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 297: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 298: return $result;
299: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
300: my @matches = grep(/^\Q$version\E.*?\.instance$/,
301: keys(%{$record}));
302: return join('<br />',($version,@matches));
303:
304:
305: } else {
306: my $result =
307: '<p>'
308: .&mt('Overall result: [_1]',
309: $record->{$version."resource.$respid.$partid.status"})
310: .'</p>';
311:
312: $result .= '<ul>';
313: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
314: keys(%{$record}));
315: foreach my $grade (sort(@grade)) {
316: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
317: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
318: $dim, $record->{$grade}).
319: '</li>';
320: }
321: $result.='</ul>';
322: return $result;
323: }
324:
1.122 ng 325: }
1.118 ng 326: return $answer;
327: }
328:
329: #-- A couple of common js functions
330: sub commonJSfunctions {
331: my $request = shift;
332: $request->print(<<COMMONJSFUNCTIONS);
333: <script type="text/javascript" language="javascript">
334: function radioSelection(radioButton) {
335: var selection=null;
336: if (radioButton.length > 1) {
337: for (var i=0; i<radioButton.length; i++) {
338: if (radioButton[i].checked) {
339: return radioButton[i].value;
340: }
341: }
342: } else {
343: if (radioButton.checked) return radioButton.value;
344: }
345: return selection;
346: }
347:
348: function pullDownSelection(selectOne) {
349: var selection="";
350: if (selectOne.length > 1) {
351: for (var i=0; i<selectOne.length; i++) {
352: if (selectOne[i].selected) {
353: return selectOne[i].value;
354: }
355: }
356: } else {
1.138 albertel 357: // only one value it must be the selected one
358: return selectOne.value;
1.118 ng 359: }
360: }
361: </script>
362: COMMONJSFUNCTIONS
363: }
364:
1.44 ng 365: #--- Dumps the class list with usernames,list of sections,
366: #--- section, ids and fullnames for each user.
367: sub getclasslist {
1.76 ng 368: my ($getsec,$filterlist) = @_;
1.291 albertel 369: my @getsec;
370: if (!ref($getsec)) {
371: if ($getsec ne '' && $getsec ne 'all') {
372: @getsec=($getsec);
373: }
374: } else {
375: @getsec=@{$getsec};
376: }
377: if (grep(/^all$/,@getsec)) { undef(@getsec); }
378:
1.56 matthew 379: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 380: # Bail out if we were unable to get the classlist
1.56 matthew 381: return if (! defined($classlist));
382: #
383: my %sections;
384: my %fullnames;
1.205 matthew 385: foreach my $student (keys(%$classlist)) {
386: my $end =
387: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
388: my $start =
389: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
390: my $id =
391: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
392: my $section =
393: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
394: my $fullname =
395: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
396: my $status =
397: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.76 ng 398: # filter students according to status selected
1.257 albertel 399: if ($filterlist && $env{'form.Status'} ne 'Any') {
400: if ($env{'form.Status'} ne $status) {
1.205 matthew 401: delete ($classlist->{$student});
1.76 ng 402: next;
403: }
404: }
1.205 matthew 405: $section = ($section ne '' ? $section : 'none');
1.106 albertel 406: if (&canview($section)) {
1.291 albertel 407: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 408: $sections{$section}++;
1.205 matthew 409: $fullnames{$student}=$fullname;
1.103 albertel 410: } else {
1.205 matthew 411: delete($classlist->{$student});
1.103 albertel 412: }
413: } else {
1.205 matthew 414: delete($classlist->{$student});
1.103 albertel 415: }
1.44 ng 416: }
417: my %seen = ();
1.56 matthew 418: my @sections = sort(keys(%sections));
419: return ($classlist,\@sections,\%fullnames);
1.44 ng 420: }
421:
1.103 albertel 422: sub canmodify {
423: my ($sec)=@_;
424: if ($perm{'mgr'}) {
425: if (!defined($perm{'mgr_section'})) {
426: # can modify whole class
427: return 1;
428: } else {
429: if ($sec eq $perm{'mgr_section'}) {
430: #can modify the requested section
431: return 1;
432: } else {
433: # can't modify the request section
434: return 0;
435: }
436: }
437: }
438: #can't modify
439: return 0;
440: }
441:
442: sub canview {
443: my ($sec)=@_;
444: if ($perm{'vgr'}) {
445: if (!defined($perm{'vgr_section'})) {
446: # can modify whole class
447: return 1;
448: } else {
449: if ($sec eq $perm{'vgr_section'}) {
450: #can modify the requested section
451: return 1;
452: } else {
453: # can't modify the request section
454: return 0;
455: }
456: }
457: }
458: #can't modify
459: return 0;
460: }
461:
1.44 ng 462: #--- Retrieve the grade status of a student for all the parts
463: sub student_gradeStatus {
1.324 albertel 464: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 465: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 466: my %partstatus = ();
467: foreach (@$partlist) {
1.128 ng 468: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 469: $status = 'nothing' if ($status eq '');
470: $partstatus{$_} = $status;
471: my $subkey = "resource.$_.submitted_by";
472: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
473: }
474: return %partstatus;
475: }
476:
1.45 ng 477: # hidden form and javascript that calls the form
478: # Use by verifyscript and viewgrades
479: # Shows a student's view of problem and submission
480: sub jscriptNform {
1.324 albertel 481: my ($symb) = @_;
1.45 ng 482: my $jscript='<script type="text/javascript" language="javascript">'."\n".
483: ' function viewOneStudent(user,domain) {'."\n".
484: ' document.onestudent.student.value = user;'."\n".
485: ' document.onestudent.userdom.value = domain;'."\n".
486: ' document.onestudent.submit();'."\n".
487: ' }'."\n".
488: '</script>'."\n";
489: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
490: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 491: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
492: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
493: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.45 ng 494: '<input type="hidden" name="command" value="submission" />'."\n".
495: '<input type="hidden" name="student" value="" />'."\n".
496: '<input type="hidden" name="userdom" value="" />'."\n".
497: '</form>'."\n";
498: return $jscript;
499: }
1.39 ng 500:
1.315 bowersj2 501: # Given the score (as a number [0-1] and the weight) what is the final
502: # point value? This function will round to the nearest tenth, third,
503: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 504: sub compute_points {
1.315 bowersj2 505: my ($score, $weight) = @_;
506:
507: my $tolerance = .00001;
508: my $points = $score * $weight;
509:
510: # Check for nearness to 1/x.
511: my $check_for_nearness = sub {
512: my ($factor) = @_;
513: my $num = ($points * $factor) + $tolerance;
514: my $floored_num = floor($num);
1.316 albertel 515: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 516: return $floored_num / $factor;
517: }
518: return $points;
519: };
520:
521: $points = $check_for_nearness->(10);
522: $points = $check_for_nearness->(3);
523: $points = $check_for_nearness->(4);
524:
525: return $points;
526: }
527:
1.44 ng 528: #------------------ End of general use routines --------------------
1.87 www 529:
530: #
531: # Find most similar essay
532: #
533:
534: sub most_similar {
535: my ($uname,$udom,$uessay)=@_;
536:
537: # ignore spaces and punctuation
538:
539: $uessay=~s/\W+/ /gs;
540:
1.282 www 541: # ignore empty submissions (occuring when only files are sent)
542:
543: unless ($uessay=~/\w+/) { return ''; }
544:
1.87 www 545: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 546: my $limit=0.6;
1.87 www 547: my $sname='';
548: my $sdom='';
549: my $scrsid='';
550: my $sessay='';
551: # go through all essays ...
552: foreach my $tkey (keys %oldessays) {
553: my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
554: # ... except the same student
1.88 www 555: if (($tname ne $uname) || ($tdom ne $udom)) {
1.87 www 556: my $tessay=$oldessays{$tkey};
557: $tessay=~s/\W+/ /gs;
558: # String similarity gives up if not even limit
1.88 www 559: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 560: # Found one
561: if ($tsimilar>$limit) {
562: $limit=$tsimilar;
563: $sname=$tname;
1.88 www 564: $sdom=$tdom;
1.87 www 565: $scrsid=$tcrsid;
566: $sessay=$oldessays{$tkey};
567: }
568: }
569: }
1.88 www 570: if ($limit>0.6) {
1.87 www 571: return ($sname,$sdom,$scrsid,$sessay,$limit);
572: } else {
573: return ('','','','',0);
574: }
575: }
576:
1.44 ng 577: #-------------------------------------------------------------------
578:
579: #------------------------------------ Receipt Verification Routines
1.45 ng 580: #
1.44 ng 581: #--- Check whether a receipt number is valid.---
582: sub verifyreceipt {
583: my $request = shift;
584:
1.257 albertel 585: my $courseid = $env{'request.course.id'};
1.184 www 586: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 587: $env{'form.receipt'};
1.44 ng 588: $receipt =~ s/[^\-\d]//g;
1.324 albertel 589: my $symb = &Apache::lonnet::symbread();
1.44 ng 590:
1.45 ng 591: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
592: $receipt.'</h3></font>'."\n".
1.326 albertel 593: '<font size=+1><b>Resource: </b>'.$env{'form.probTitle'}.'</font><br /><br />'."\n";
1.44 ng 594:
595: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 596: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 597:
598: my $receiptparts=0;
1.257 albertel 599: if ($env{"course.$courseid.receiptalg"} eq 'receipt2') { $receiptparts=1; }
1.177 albertel 600: my $parts=['0'];
1.324 albertel 601: if ($receiptparts) { ($parts)=&response_type($symb); }
1.294 albertel 602: foreach (sort
603: {
604: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
605: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
606: }
607: return $a cmp $b;
608: } (keys(%$fullname))) {
1.44 ng 609: my ($uname,$udom)=split(/\:/);
1.177 albertel 610: foreach my $part (@$parts) {
611: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
612: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
613: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
614: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
615: '<td> '.$uname.' </td>'.
616: '<td> '.$udom.' </td>';
617: if ($receiptparts) {
618: $contents.='<td> '.$part.' </td>';
619: }
620: $contents.='</tr>'."\n";
621:
622: $matches++;
623: }
1.44 ng 624: }
625: }
626: if ($matches == 0) {
627: $string = $title.'No match found for the above receipt.';
628: } else {
1.324 albertel 629: $string = &jscriptNform($symb).$title.
1.44 ng 630: 'The above receipt matches the following student'.
631: ($matches <= 1 ? '.' : 's.')."\n".
632: '<table border="0"><tr><td bgcolor="#777777">'."\n".
633: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
634: '<td><b> Fullname </b></td>'."\n".
635: '<td><b> Username </b></td>'."\n".
1.177 albertel 636: '<td><b> Domain </b></td>';
637: if ($receiptparts) {
638: $string.='<td> Problem Part </td>';
639: }
640: $string.='</tr>'."\n".$contents.
1.44 ng 641: '</table></td></tr></table>'."\n";
642: }
1.324 albertel 643: return $string.&show_grading_menu_form($symb);
1.44 ng 644: }
645:
646: #--- This is called by a number of programs.
647: #--- Called from the Grading Menu - View/Grade an individual student
648: #--- Also called directly when one clicks on the subm button
649: # on the problem page.
1.30 ng 650: sub listStudents {
1.41 ng 651: my ($request) = shift;
1.49 albertel 652:
1.324 albertel 653: my ($symb) = &get_symb($request);
1.257 albertel 654: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
655: my $cnum = $env{"course.$env{'request.course.id'}.num"};
656: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
657: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
658:
659: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
660: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
661: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 662:
1.118 ng 663: my $result='<h3><font color="#339933"> '.$viewgrade.
664: ' Submissions for a Student or a Group of Students</font></h3>';
665:
1.324 albertel 666: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 667:
1.45 ng 668: $request->print(<<LISTJAVASCRIPT);
669: <script type="text/javascript" language="javascript">
1.110 ng 670: function checkSelect(checkBox) {
671: var ctr=0;
672: var sense="";
673: if (checkBox.length > 1) {
674: for (var i=0; i<checkBox.length; i++) {
675: if (checkBox[i].checked) {
676: ctr++;
677: }
678: }
679: sense = "a student or group of students";
680: } else {
681: if (checkBox.checked) {
682: ctr = 1;
683: }
684: sense = "the student";
685: }
686: if (ctr == 0) {
1.126 ng 687: alert("Please select "+sense+" before clicking on the Next button.");
1.110 ng 688: return false;
689: }
690: document.gradesub.submit();
691: }
692:
693: function reLoadList(formname) {
1.112 ng 694: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 695: formname.command.value = 'submission';
696: formname.submit();
697: }
1.45 ng 698: </script>
699: LISTJAVASCRIPT
700:
1.118 ng 701: &commonJSfunctions($request);
1.41 ng 702: $request->print($result);
1.39 ng 703:
1.257 albertel 704: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
1.119 ng 705: my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
1.154 albertel 706: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
707: "\n".$table.
1.267 albertel 708: ' <b>View Problem Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
709: '<label><input type="radio" name="vProb" value="yes" /> one student </label>'."\n".
710: '<label><input type="radio" name="vProb" value="all" /> all students </label><br />'."\n".
711: ' <b>View Answer: </b><label><input type="radio" name="vAns" value="no" /> no </label>'."\n".
712: '<label><input type="radio" name="vAns" value="yes" /> one student </label>'."\n".
713: '<label><input type="radio" name="vAns" value="all" checked="on" /> all students </label><br />'."\n".
1.49 albertel 714: ' <b>Submissions: </b>'."\n";
1.257 albertel 715: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.267 albertel 716: $gradeTable.='<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only </label>'."\n";
1.49 albertel 717: }
1.110 ng 718:
1.257 albertel 719: my $saveStatus = $env{'form.Status'} eq '' ? 'Active' : $env{'form.Status'};
720: $env{'form.Status'} = $saveStatus;
1.110 ng 721:
1.267 albertel 722: $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n".
723: '<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n".
724: '<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n".
1.348 bowersj2 725: '<label><input type="radio" name="lastSub" value="all" /> all details</label><br />'."\n".
726: ' <b>Grading Increments:</b> <select name="increment">'.
727: '<option value="1">Whole Points</option>'.
728: '<option value=".5">Half Points</option>'.
1.349 ! albertel 729: '<option value=".25">Quarter Points</option>'.
! 730: '<option value=".1">Tenths of a Point</option>'.
1.348 bowersj2 731: '</select>'.
732:
1.45 ng 733: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
734: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 735: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
736: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
737: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
738: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.48 albertel 739: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.110 ng 740: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
741:
1.257 albertel 742: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
743: $gradeTable.='<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 744: } else {
745: $gradeTable.='<b>Student Status:</b> '.
746: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
747: }
1.112 ng 748:
1.126 ng 749: $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
750: 'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110 ng 751: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 752:
753: # checkall buttons
754: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 755: $gradeTable.='<input type="button" '."\n".
1.45 ng 756: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.249 albertel 757: 'value="Next->" /> <br />'."\n";
758: $gradeTable.=&check_buttons();
1.267 albertel 759: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="on" />Check For Plagiarism</label>';
1.249 albertel 760: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1');
1.45 ng 761: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110 ng 762: '<table border="0"><tr bgcolor="#e6ffff">';
763: my $loop = 0;
764: while ($loop < 2) {
1.126 ng 765: $gradeTable.='<td><b> No.</b> </td><td><b> Select </b></td>'.
1.250 albertel 766: '<td>'.&nameUserString('header').' Section/Group</td>';
1.301 albertel 767: if ($env{'form.showgrading'} eq 'yes'
768: && $submitonly ne 'queued'
769: && $submitonly ne 'all') {
1.110 ng 770: foreach (sort(@$partlist)) {
1.324 albertel 771: my $display_part=&get_display_part((split(/_/))[0],$symb);
1.207 albertel 772: $gradeTable.='<td><b> Part: '.$display_part.
773: ' Status </b></td>';
1.110 ng 774: }
1.301 albertel 775: } elsif ($submitonly eq 'queued') {
776: $gradeTable.='<td><b> '.&mt('Queue Status').' </b></td>';
1.110 ng 777: }
778: $loop++;
1.126 ng 779: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 780: }
1.45 ng 781: $gradeTable.='</tr>'."\n";
1.41 ng 782:
1.45 ng 783: my $ctr = 0;
1.294 albertel 784: foreach my $student (sort
785: {
786: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
787: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
788: }
789: return $a cmp $b;
790: }
791: (keys(%$fullname))) {
1.41 ng 792: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 793:
1.110 ng 794: my %status = ();
1.301 albertel 795:
796: if ($submitonly eq 'queued') {
797: my %queue_status =
798: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
799: $udom,$uname);
800: next if (!defined($queue_status{'gradingqueue'}));
801: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
802: }
803:
804: if ($env{'form.showgrading'} eq 'yes'
805: && $submitonly ne 'queued'
806: && $submitonly ne 'all') {
1.324 albertel 807: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 808: my $submitted = 0;
1.164 albertel 809: my $graded = 0;
1.248 albertel 810: my $incorrect = 0;
1.110 ng 811: foreach (keys(%status)) {
1.145 albertel 812: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 813: $graded = 1 if ($status{$_} =~ /^ungraded/);
814: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
815:
1.110 ng 816: my ($foo,$partid,$foo1) = split(/\./,$_);
817: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 818: $submitted = 0;
1.150 albertel 819: my ($part)=split(/\./,$partid);
1.110 ng 820: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 821: $student.':'.$part.':submitted_by" value="'.
1.110 ng 822: $status{'resource.'.$partid.'.submitted_by'}.'" />';
823: }
1.41 ng 824: }
1.248 albertel 825:
1.156 albertel 826: next if (!$submitted && ($submitonly eq 'yes' ||
827: $submitonly eq 'incorrect' ||
828: $submitonly eq 'graded'));
1.248 albertel 829: next if (!$graded && ($submitonly eq 'graded'));
830: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 831: }
1.34 ng 832:
1.45 ng 833: $ctr++;
1.249 albertel 834: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
835:
1.104 albertel 836: if ( $perm{'vgr'} eq 'F' ) {
1.110 ng 837: $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126 ng 838: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 839: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
840: $student.':'.$$fullname{$student}.':::SECTION'.$section.
841: ') " /> </label></td>'."\n".'<td>'.
842: &nameUserString(undef,$$fullname{$student},$uname,$udom).
843: ' '.$section.'</td>'."\n";
1.110 ng 844:
1.257 albertel 845: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.110 ng 846: foreach (sort keys(%status)) {
847: next if (/^resource.*?submitted_by$/);
1.276 albertel 848: $gradeTable.='<td align="center"> '.$status{$_}.' </td>'."\n";
1.110 ng 849: }
1.41 ng 850: }
1.126 ng 851: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110 ng 852: $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41 ng 853: }
854: }
1.110 ng 855: if ($ctr%2 ==1) {
1.126 ng 856: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 857: if ($env{'form.showgrading'} eq 'yes'
858: && $submitonly ne 'queued'
859: && $submitonly ne 'all') {
1.110 ng 860: foreach (@$partlist) {
861: $gradeTable.='<td> </td>';
862: }
1.301 albertel 863: } elsif ($submitonly eq 'queued') {
864: $gradeTable.='<td> </td>';
1.110 ng 865: }
866: $gradeTable.='</tr>';
867: }
868:
1.249 albertel 869: $gradeTable.='</table></td></tr></table>'."\n".
1.45 ng 870: '<input type="button" '.
871: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126 ng 872: 'value="Next->" /></form>'."\n";
1.45 ng 873: if ($ctr == 0) {
1.96 albertel 874: my $num_students=(scalar(keys(%$fullname)));
875: if ($num_students eq 0) {
876: $gradeTable='<br /> <font color="red">There are no students currently enrolled.</font>';
877: } else {
1.171 albertel 878: my $submissions='submissions';
879: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
880: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 881: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.96 albertel 882: $gradeTable='<br /> <font color="red">'.
1.171 albertel 883: 'No '.$submissions.' found for this resource for any students. ('.$num_students.
884: ' students checked for '.$submissions.')</font><br />';
1.96 albertel 885: }
1.46 ng 886: } elsif ($ctr == 1) {
887: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 888: }
1.324 albertel 889: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 890: $request->print($gradeTable);
1.44 ng 891: return '';
1.10 ng 892: }
893:
1.44 ng 894: #---- Called from the listStudents routine
1.249 albertel 895:
896: sub check_script {
897: my ($form, $type)=@_;
898: my $chkallscript='<script type="text/javascript">
899: function checkall() {
900: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
901: ele = document.forms.'.$form.'.elements[i];
902: if (ele.name == "'.$type.'") {
903: document.forms.'.$form.'.elements[i].checked=true;
904: }
905: }
906: }
907:
908: function checksec() {
909: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
910: ele = document.forms.'.$form.'.elements[i];
911: string = document.forms.'.$form.'.chksec.value;
912: if
913: (ele.value.indexOf(":::SECTION"+string)>0) {
914: document.forms.'.$form.'.elements[i].checked=true;
915: }
916: }
917: }
918:
919:
920: function uncheckall() {
921: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
922: ele = document.forms.'.$form.'.elements[i];
923: if (ele.name == "'.$type.'") {
924: document.forms.'.$form.'.elements[i].checked=false;
925: }
926: }
927: }
928:
929: </script>'."\n";
930: return $chkallscript;
931: }
932:
933: sub check_buttons {
934: my $buttons.='<input type="button" onclick="checkall()" value="Check All" />';
935: $buttons.='<input type="button" onclick="uncheckall()" value="Uncheck All" /> ';
936: $buttons.='<input type="button" onclick="checksec()" value="Check Section/Group" />';
937: $buttons.='<input type="text" size="5" name="chksec" /> ';
938: return $buttons;
939: }
940:
1.44 ng 941: # Displays the submissions for one student or a group of students
1.34 ng 942: sub processGroup {
1.41 ng 943: my ($request) = shift;
944: my $ctr = 0;
1.155 albertel 945: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 946: my $total = scalar(@stuchecked)-1;
1.45 ng 947:
1.41 ng 948: foreach (@stuchecked) {
949: my ($uname,$udom,$fullname) = split(/:/);
1.257 albertel 950: $env{'form.student'} = $uname;
951: $env{'form.userdom'} = $udom;
952: $env{'form.fullname'} = $fullname;
1.41 ng 953: &submission($request,$ctr,$total);
954: $ctr++;
955: }
956: return '';
1.35 ng 957: }
1.34 ng 958:
1.44 ng 959: #------------------------------------------------------------------------------------
960: #
961: #-------------------------- Next few routines handles grading by student, essentially
962: # handles essay response type problem/part
963: #
964: #--- Javascript to handle the submission page functionality ---
965: sub sub_page_js {
966: my $request = shift;
967: $request->print(<<SUBJAVASCRIPT);
968: <script type="text/javascript" language="javascript">
1.71 ng 969: function updateRadio(formname,id,weight) {
1.125 ng 970: var gradeBox = formname["GD_BOX"+id];
971: var radioButton = formname["RADVAL"+id];
972: var oldpts = formname["oldpts"+id].value;
1.72 ng 973: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 974: gradeBox.value = pts;
975: var resetbox = false;
976: if (isNaN(pts) || pts < 0) {
977: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
978: for (var i=0; i<radioButton.length; i++) {
979: if (radioButton[i].checked) {
980: gradeBox.value = i;
981: resetbox = true;
982: }
983: }
984: if (!resetbox) {
985: formtextbox.value = "";
986: }
987: return;
1.44 ng 988: }
1.71 ng 989:
990: if (pts > weight) {
991: var resp = confirm("You entered a value ("+pts+
992: ") greater than the weight for the part. Accept?");
993: if (resp == false) {
1.125 ng 994: gradeBox.value = oldpts;
1.71 ng 995: return;
996: }
1.44 ng 997: }
1.13 albertel 998:
1.71 ng 999: for (var i=0; i<radioButton.length; i++) {
1000: radioButton[i].checked=false;
1001: if (pts == i && pts != "") {
1002: radioButton[i].checked=true;
1003: }
1004: }
1005: updateSelect(formname,id);
1.125 ng 1006: formname["stores"+id].value = "0";
1.41 ng 1007: }
1.5 albertel 1008:
1.72 ng 1009: function writeBox(formname,id,pts) {
1.125 ng 1010: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1011: if (checkSolved(formname,id) == 'update') {
1012: gradeBox.value = pts;
1013: } else {
1.125 ng 1014: var oldpts = formname["oldpts"+id].value;
1.72 ng 1015: gradeBox.value = oldpts;
1.125 ng 1016: var radioButton = formname["RADVAL"+id];
1.71 ng 1017: for (var i=0; i<radioButton.length; i++) {
1018: radioButton[i].checked=false;
1.72 ng 1019: if (i == oldpts) {
1.71 ng 1020: radioButton[i].checked=true;
1021: }
1022: }
1.41 ng 1023: }
1.125 ng 1024: formname["stores"+id].value = "0";
1.71 ng 1025: updateSelect(formname,id);
1026: return;
1.41 ng 1027: }
1.44 ng 1028:
1.71 ng 1029: function clearRadBox(formname,id) {
1030: if (checkSolved(formname,id) == 'noupdate') {
1031: updateSelect(formname,id);
1032: return;
1033: }
1.125 ng 1034: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1035: for (var i=0; i<gradeSelect.length; i++) {
1036: if (gradeSelect[i].selected) {
1037: var selectx=i;
1038: }
1039: }
1.125 ng 1040: var stores = formname["stores"+id];
1.71 ng 1041: if (selectx == stores.value) { return };
1.125 ng 1042: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1043: gradeBox.value = "";
1.125 ng 1044: var radioButton = formname["RADVAL"+id];
1.71 ng 1045: for (var i=0; i<radioButton.length; i++) {
1046: radioButton[i].checked=false;
1047: }
1048: stores.value = selectx;
1049: }
1.5 albertel 1050:
1.71 ng 1051: function checkSolved(formname,id) {
1.125 ng 1052: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1053: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1054: if (!reply) {return "noupdate";}
1.120 ng 1055: formname.overRideScore.value = 'yes';
1.41 ng 1056: }
1.71 ng 1057: return "update";
1.13 albertel 1058: }
1.71 ng 1059:
1060: function updateSelect(formname,id) {
1.125 ng 1061: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1062: return;
1.41 ng 1063: }
1.33 ng 1064:
1.121 ng 1065: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1066: function checksubmit(formname,val,total,parttot) {
1.121 ng 1067: formname.gradeOpt.value = val;
1.71 ng 1068: if (val == "Save & Next") {
1069: for (i=0;i<=total;i++) {
1070: for (j=0;j<parttot;j++) {
1.125 ng 1071: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1072: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1073: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1074: if (points == "") {
1.125 ng 1075: var name = formname["name"+i].value;
1.129 ng 1076: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1077: var resp = confirm("You did not assign a score for "+studentID+
1078: ", part "+partid+". Continue?");
1.71 ng 1079: if (resp == false) {
1.125 ng 1080: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1081: return false;
1082: }
1083: }
1084: }
1085:
1086: }
1087: }
1088:
1089: }
1.121 ng 1090: if (val == "Grade Student") {
1091: formname.showgrading.value = "yes";
1092: if (formname.Status.value == "") {
1093: formname.Status.value = "Active";
1094: }
1095: formname.studentNo.value = total;
1096: }
1.120 ng 1097: formname.submit();
1098: }
1099:
1.71 ng 1100: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1101: function checkSubmitPage(formname,total) {
1102: noscore = new Array(100);
1103: var ptr = 0;
1104: for (i=1;i<total;i++) {
1.125 ng 1105: var partid = formname["q_"+i].value;
1.127 ng 1106: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1107: var points = formname["GD_BOX"+i+"_"+partid].value;
1108: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1109: if (points == "" && status != "correct_by_student") {
1110: noscore[ptr] = i;
1111: ptr++;
1112: }
1113: }
1114: }
1115: if (ptr != 0) {
1116: var sense = ptr == 1 ? ": " : "s: ";
1117: var prolist = "";
1118: if (ptr == 1) {
1119: prolist = noscore[0];
1120: } else {
1121: var i = 0;
1122: while (i < ptr-1) {
1123: prolist += noscore[i]+", ";
1124: i++;
1125: }
1126: prolist += "and "+noscore[i];
1127: }
1128: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1129: if (resp == false) {
1130: return false;
1131: }
1132: }
1.45 ng 1133:
1.71 ng 1134: formname.submit();
1135: }
1136: </script>
1137: SUBJAVASCRIPT
1138: }
1.45 ng 1139:
1.71 ng 1140: #--- javascript for essay type problem --
1141: sub sub_page_kw_js {
1142: my $request = shift;
1.80 ng 1143: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1144: &commonJSfunctions($request);
1.219 www 1145: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1146: $docopen=~s/^document\.//;
1.71 ng 1147: $request->print(<<SUBJAVASCRIPT);
1148: <script type="text/javascript" language="javascript">
1.45 ng 1149:
1.44 ng 1150: //===================== Show list of keywords ====================
1.122 ng 1151: function keywords(formname) {
1152: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1153: if (nret==null) return;
1.122 ng 1154: formname.keywords.value = nret;
1.44 ng 1155:
1.122 ng 1156: if (formname.keywords.value != "") {
1.128 ng 1157: formname.refresh.value = "on";
1.122 ng 1158: formname.submit();
1.44 ng 1159: }
1160: return;
1161: }
1162:
1163: //===================== Script to view submitted by ==================
1164: function viewSubmitter(submitter) {
1165: document.SCORE.refresh.value = "on";
1166: document.SCORE.NCT.value = "1";
1167: document.SCORE.unamedom0.value = submitter;
1168: document.SCORE.submit();
1169: return;
1170: }
1171:
1172: //===================== Script to add keyword(s) ==================
1173: function getSel() {
1174: if (document.getSelection) txt = document.getSelection();
1175: else if (document.selection) txt = document.selection.createRange().text;
1176: else return;
1177: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1178: if (cleantxt=="") {
1.46 ng 1179: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 1180: return;
1181: }
1182: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1183: if (nret==null) return;
1.127 ng 1184: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1185: if (document.SCORE.keywords.value != "") {
1.127 ng 1186: document.SCORE.refresh.value = "on";
1.44 ng 1187: document.SCORE.submit();
1188: }
1189: return;
1190: }
1191:
1192: //====================== Script for composing message ==============
1.80 ng 1193: // preload images
1194: img1 = new Image();
1195: img1.src = "$iconpath/mailbkgrd.gif";
1196: img2 = new Image();
1197: img2.src = "$iconpath/mailto.gif";
1198:
1.44 ng 1199: function msgCenter(msgform,usrctr,fullname) {
1200: var Nmsg = msgform.savemsgN.value;
1201: savedMsgHeader(Nmsg,usrctr,fullname);
1202: var subject = msgform.msgsub.value;
1.127 ng 1203: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1204: re = /msgsub/;
1205: var shwsel = "";
1206: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1207: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1208: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1209: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1210: var testmsg = "savemsg"+i+",";
1211: re = new RegExp(testmsg,"g");
1.44 ng 1212: shwsel = "";
1213: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1214: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1215: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1216: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1217: //any < is already converted to <, etc. However, only once!!
1.44 ng 1218: }
1.125 ng 1219: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1220: shwsel = "";
1221: re = /newmsg/;
1222: if (re.test(msgchk)) { shwsel = "checked" }
1223: newMsg(newmsg,shwsel);
1224: msgTail();
1225: return;
1226: }
1227:
1.123 ng 1228: function checkEntities(strx) {
1229: if (strx.length == 0) return strx;
1230: var orgStr = ["&", "<", ">", '"'];
1231: var newStr = ["&", "<", ">", """];
1232: var counter = 0;
1233: while (counter < 4) {
1234: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1235: counter++;
1236: }
1237: return strx;
1238: }
1239:
1240: function strReplace(strx, orgStr, newStr) {
1241: return strx.split(orgStr).join(newStr);
1242: }
1243:
1.44 ng 1244: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1245: var height = 70*Nmsg+250;
1.44 ng 1246: var scrollbar = "no";
1247: if (height > 600) {
1248: height = 600;
1249: scrollbar = "yes";
1250: }
1.118 ng 1251: var xpos = (screen.width-600)/2;
1252: xpos = (xpos < 0) ? '0' : xpos;
1253: var ypos = (screen.height-height)/2-30;
1254: ypos = (ypos < 0) ? '0' : ypos;
1255:
1.206 albertel 1256: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1257: pWin.focus();
1258: pDoc = pWin.document;
1.219 www 1259: pDoc.$docopen;
1.76 ng 1260: pDoc.write("<html><head>");
1261: pDoc.write("<title>Message Central</title>");
1262:
1263: pDoc.write("<script language=javascript>");
1264: pDoc.write("function checkInput() {");
1.123 ng 1265: pDoc.write(" opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);");
1.76 ng 1266: pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
1267: pDoc.write(" var usrctr = document.msgcenter.usrctr.value;");
1.125 ng 1268: pDoc.write(" var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];");
1.123 ng 1269: pDoc.write(" newval.value = opener.checkEntities(document.msgcenter.newmsg.value);");
1.76 ng 1270:
1271: pDoc.write(" var msgchk = \\"\\";");
1272: pDoc.write(" if (document.msgcenter.subchk.checked) {");
1273: pDoc.write(" msgchk = \\"msgsub,\\";");
1274: pDoc.write(" }");
1.80 ng 1275: pDoc.write(" var includemsg = 0;");
1276: pDoc.write(" for (var i=1; i<=nmsg; i++) {");
1.125 ng 1277: pDoc.write(" var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];");
1278: pDoc.write(" var frmmsg = document.msgcenter[\\"msg\\"+i];");
1.123 ng 1279: pDoc.write(" opnmsg.value = opener.checkEntities(frmmsg.value);");
1.125 ng 1280: pDoc.write(" var showflg = opener.document.SCORE[\\"shownOnce\\"+i];");
1.123 ng 1281: pDoc.write(" showflg.value = \\"1\\";");
1.125 ng 1282: pDoc.write(" var chkbox = document.msgcenter[\\"msgn\\"+i];");
1.76 ng 1283: pDoc.write(" if (chkbox.checked) {");
1284: pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1.80 ng 1285: pDoc.write(" includemsg = 1;");
1.76 ng 1286: pDoc.write(" }");
1287: pDoc.write(" }");
1288: pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
1289: pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
1.80 ng 1290: pDoc.write(" includemsg = 1;");
1291: pDoc.write(" }");
1.125 ng 1292: pDoc.write(" imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];");
1.84 ng 1293: pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
1.125 ng 1294: pDoc.write(" var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];");
1.76 ng 1295: pDoc.write(" includemsg.value = msgchk;");
1296:
1297: pDoc.write(" self.close()");
1298:
1299: pDoc.write("}");
1300:
1301: pDoc.write("<");
1302: pDoc.write("/script>");
1303:
1304: pDoc.write("</head><body bgcolor=white>");
1305:
1306: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1307: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.326 albertel 1308: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br /><br />");
1.76 ng 1309:
1310: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1311: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1312: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 1313: }
1314: function displaySubject(msg,shwsel) {
1.76 ng 1315: pDoc = pWin.document;
1316: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1317: pDoc.write("<td>Subject</td>");
1318: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1319: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 1320: }
1321:
1.72 ng 1322: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1323: pDoc = pWin.document;
1324: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1325: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
1326: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1327: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 1328: }
1329:
1330: function newMsg(newmsg,shwsel) {
1.76 ng 1331: pDoc = pWin.document;
1332: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1333: pDoc.write("<td align=\\"center\\">New</td>");
1334: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1335: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 1336: }
1337:
1338: function msgTail() {
1.76 ng 1339: pDoc = pWin.document;
1340: pDoc.write("</table>");
1341: pDoc.write("</td></tr></table> ");
1342: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1343: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1344: pDoc.write("</form>");
1345: pDoc.write("</body></html>");
1.128 ng 1346: pDoc.close();
1.44 ng 1347: }
1348:
1349: //====================== Script for keyword highlight options ==============
1350: function kwhighlight() {
1351: var kwclr = document.SCORE.kwclr.value;
1352: var kwsize = document.SCORE.kwsize.value;
1353: var kwstyle = document.SCORE.kwstyle.value;
1354: var redsel = "";
1355: var grnsel = "";
1356: var blusel = "";
1357: if (kwclr=="red") {var redsel="checked"};
1358: if (kwclr=="green") {var grnsel="checked"};
1359: if (kwclr=="blue") {var blusel="checked"};
1360: var sznsel = "";
1361: var sz1sel = "";
1362: var sz2sel = "";
1363: if (kwsize=="0") {var sznsel="checked"};
1364: if (kwsize=="+1") {var sz1sel="checked"};
1365: if (kwsize=="+2") {var sz2sel="checked"};
1366: var synsel = "";
1367: var syisel = "";
1368: var sybsel = "";
1369: if (kwstyle=="") {var synsel="checked"};
1370: if (kwstyle=="<i>") {var syisel="checked"};
1371: if (kwstyle=="<b>") {var sybsel="checked"};
1372: highlightCentral();
1373: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1374: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1375: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1376: highlightend();
1377: return;
1378: }
1379:
1380: function highlightCentral() {
1.76 ng 1381: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1382: var xpos = (screen.width-400)/2;
1383: xpos = (xpos < 0) ? '0' : xpos;
1384: var ypos = (screen.height-330)/2-30;
1385: ypos = (ypos < 0) ? '0' : ypos;
1386:
1.206 albertel 1387: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1388: hwdWin.focus();
1389: var hDoc = hwdWin.document;
1.219 www 1390: hDoc.$docopen;
1.76 ng 1391: hDoc.write("<html><head>");
1392: hDoc.write("<title>Highlight Central</title>");
1393:
1394: hDoc.write("<script language=javascript>");
1395: hDoc.write("function updateChoice(flag) {");
1.118 ng 1396: hDoc.write(" opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);");
1397: hDoc.write(" opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);");
1398: hDoc.write(" opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);");
1.76 ng 1399: hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";");
1400: hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
1401: hDoc.write(" opener.document.SCORE.submit();");
1402: hDoc.write(" }");
1403: hDoc.write(" self.close()");
1404: hDoc.write("}");
1405:
1406: hDoc.write("<");
1407: hDoc.write("/script>");
1408:
1409: hDoc.write("</head><body bgcolor=white>");
1410:
1411: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.326 albertel 1412: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br /><br />");
1.76 ng 1413:
1414: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1415: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1416: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 1417: }
1418:
1419: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1420: var hDoc = hwdWin.document;
1421: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1422: hDoc.write("<td align=\\"left\\">");
1423: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1424: hDoc.write("<td align=\\"left\\">");
1425: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1426: hDoc.write("<td align=\\"left\\">");
1427: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1428: hDoc.write("</tr>");
1.44 ng 1429: }
1430:
1431: function highlightend() {
1.76 ng 1432: var hDoc = hwdWin.document;
1433: hDoc.write("</table>");
1434: hDoc.write("</td></tr></table> ");
1435: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1436: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1437: hDoc.write("</form>");
1438: hDoc.write("</body></html>");
1.128 ng 1439: hDoc.close();
1.44 ng 1440: }
1441:
1442: </script>
1443: SUBJAVASCRIPT
1444: }
1445:
1.349 ! albertel 1446: sub get_increment {
1.348 bowersj2 1447: my $increment = $env{'form.increment'};
1448: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1449: $increment != .1) {
1450: $increment = 1;
1451: }
1452: return $increment;
1453: }
1454:
1.71 ng 1455: #--- displays the grading box, used in essay type problem and grading by page/sequence
1456: sub gradeBox {
1.322 albertel 1457: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.71 ng 1458: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1459: '/check.gif" height="16" border="0" />';
1460: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1461: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1462: '<font color="red">problem weight assigned by computer</font>');
1463: $wgt = ($wgt > 0 ? $wgt : '1');
1464: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1465: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1466: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.324 albertel 1467: my $display_part=&get_display_part($partid,$symb);
1.270 albertel 1468: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1469: [$partid]);
1470: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1471: if ($last_resets{$partid}) {
1472: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1473: }
1.71 ng 1474: $result.='<table border="0"><tr><td>'.
1.207 albertel 1475: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1476: my $ctr = 0;
1.348 bowersj2 1477: my $thisweight = 0;
1.349 ! albertel 1478: my $increment = &get_increment();
1.71 ng 1479: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1480: while ($thisweight<=$wgt) {
1.288 albertel 1481: $result.= '<td><nobr><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1482: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1483: $thisweight.')" value="'.$thisweight.'" '.
1484: ($score eq $thisweight ? 'checked':'').' /> '.$thisweight."</label></nobr></td>\n";
1.71 ng 1485: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1486: $thisweight += $increment;
1.71 ng 1487: $ctr++;
1488: }
1489: $result.='</tr></table>';
1490: $result.='</td><td> <b>or</b> </td>'."\n";
1491: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1492: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1493: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1494: $wgt.')" /></td>'."\n";
1495: $result.='<td>/'.$wgt.' '.$wgtmsg.
1496: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1497: ' </td><td>'."\n";
1498: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1499: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1500: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1501: $result.='<option> </option>'.
1.125 ng 1502: '<option selected="on">excused</option>';
1.71 ng 1503: } else {
1504: $result.='<option selected="on"> </option>'.
1.125 ng 1505: '<option>excused</option>';
1.71 ng 1506: }
1.125 ng 1507: $result.='<option>reset status</option></select>'."\n";
1.71 ng 1508: $result.="  \n";
1509: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1510: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1511: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1512: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1513: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1514: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1515: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1516: $aggtries.'" />'."\n";
1.71 ng 1517: $result.='</td></tr></table>'."\n";
1.323 banghart 1518: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1519: return $result;
1520: }
1.322 albertel 1521:
1522: sub handback_box {
1.323 banghart 1523: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1524: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1525: my (@respids);
1526: foreach my $part_resp (sort(keys(%$handgrade))) {
1527: my ($part,$resp) = split(/_/,$part_resp);
1528: if ($part eq $partid) {
1529: push @respids,$resp;
1530: }
1531: }
1.318 banghart 1532: my $result;
1.323 banghart 1533: foreach my $respid (@respids) {
1.322 albertel 1534: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1535: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1536: next if (!@$files);
1537: my $file_counter = 1;
1.313 banghart 1538: foreach my $file (@$files) {
1.347 banghart 1539: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1540: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1541: $file_disp = "$name.$ext";
1542: $file = $file_path.$file_disp;
1.322 albertel 1543: $result.=&mt('Return commented version of [_1] to student.',
1544: '<span class="filename">'.$file_disp.'</span>');
1.323 banghart 1545: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1546: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.322 albertel 1547: $file_counter++;
1548: }
1.313 banghart 1549: }
1.318 banghart 1550: return $result;
1.71 ng 1551: }
1.44 ng 1552:
1.58 albertel 1553: sub show_problem {
1.144 albertel 1554: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
1555: my $rendered;
1.329 albertel 1556: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1557: if ($mode eq 'both' or $mode eq 'text') {
1558: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.257 albertel 1559: $env{'request.course.id'});
1.144 albertel 1560: }
1.58 albertel 1561: if ($removeform) {
1562: $rendered=~s|<form(.*?)>||g;
1563: $rendered=~s|</form>||g;
1564: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
1565: }
1.144 albertel 1566: my $companswer;
1567: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1568: &Apache::lonxml::restore_problem_counter();
1.144 albertel 1569: $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1.257 albertel 1570: $env{'request.course.id'});
1.144 albertel 1571: }
1.58 albertel 1572: if ($removeform) {
1573: $companswer=~s|<form(.*?)>||g;
1574: $companswer=~s|</form>||g;
1.144 albertel 1575: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1576: }
1577: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1578: $result.='<table border="0" width="100%">';
1.144 albertel 1579: if ($viewon) {
1580: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1581: if ($mode eq 'both' or $mode eq 'text') {
1582: $result.='View of the problem - ';
1583: } else {
1584: $result.='Correct answer: ';
1585: }
1.257 albertel 1586: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1587: }
1588: if ($mode eq 'both') {
1589: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1590: $result.='<b>Correct answer:</b><br />'.$companswer;
1591: } elsif ($mode eq 'text') {
1592: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1593: } elsif ($mode eq 'answer') {
1594: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1595: }
1.58 albertel 1596: $result.='</td></tr></table>';
1597: $result.='</td></tr></table><br />';
1.71 ng 1598: return $result;
1.58 albertel 1599: }
1600:
1.44 ng 1601: # --------------------------- show submissions of a student, option to grade
1602: sub submission {
1603: my ($request,$counter,$total) = @_;
1604:
1.257 albertel 1605: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1606: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1607: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1608: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1609:
1.324 albertel 1610: my $symb = &get_symb($request);
1611: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1612:
1613: if (!&canview($usec)) {
1.116 ng 1614: $request->print('<font color="red">Unable to view requested student.('.
1.222 albertel 1615: $uname.'@'.$udom.' in section '.$usec.' in course id '.
1.257 albertel 1616: $env{'request.course.id'}.')</font>');
1.324 albertel 1617: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1618: return;
1619: }
1620:
1.257 albertel 1621: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1622: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1623: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1624: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.122 ng 1625: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1626: '/check.gif" height="16" border="0" />';
1.41 ng 1627:
1628: # header info
1629: if ($counter == 0) {
1630: &sub_page_js($request);
1.257 albertel 1631: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1632: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1633: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.76 ng 1634:
1.45 ng 1635: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.257 albertel 1636: '<font size=+1> <b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");
1.118 ng 1637:
1.257 albertel 1638: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1639: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1640: $checkIcon.' symbol.'."\n";
1641: $request->print($checkMark);
1642: }
1.41 ng 1643:
1.44 ng 1644: # option to display problem, only once else it cause problems
1645: # with the form later since the problem has a form.
1.257 albertel 1646: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1647: my $mode;
1.257 albertel 1648: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1649: $mode='both';
1.257 albertel 1650: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1651: $mode='text';
1.257 albertel 1652: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1653: $mode='answer';
1654: }
1.329 albertel 1655: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1656: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1657: }
1658:
1.44 ng 1659: # kwclr is the only variable that is guaranteed to be non blank
1660: # if this subroutine has been called once.
1.41 ng 1661: my %keyhash = ();
1.257 albertel 1662: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1663: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1664: $env{'course.'.$env{'request.course.id'}.'.domain'},
1665: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1666:
1.257 albertel 1667: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1668: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1669: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1670: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1671: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1672: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1673: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1674: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1675: }
1.257 albertel 1676: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1677:
1.303 banghart 1678: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1679: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1680: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1681: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1682: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1683: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1684: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1685: '<input type="hidden" name="studentNo" value="" />'."\n".
1686: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1687: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 1688: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1689: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1690: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1691: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.326 albertel 1692: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
1693: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1694: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1695: '<input type="hidden" name="NCT"'.
1.257 albertel 1696: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1697: if ($env{'form.handgrade'} eq 'yes') {
1698: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1699: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1700: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1701: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1702: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1703: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1704: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1705: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1706: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1707: }
1.123 ng 1708: }
1.41 ng 1709:
1710: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1711: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1712: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1713: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1714: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1715: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1716: '" />'."\n".
1717: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1718: $cts++;
1719: }
1720: $request->print($prnmsg);
1.32 ng 1721:
1.257 albertel 1722: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1723: #
1724: # Print out the keyword options line
1725: #
1.41 ng 1726: $request->print(<<KEYWORDS);
1.38 ng 1727: <b>Keyword Options:</b>
1.122 ng 1728: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1729: <a href="#" onMouseDown="javascript:getSel(); return false"
1730: CLASS="page">Paste Selection to List</a>
1731: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1732: KEYWORDS
1.88 www 1733: #
1734: # Load the other essays for similarity check
1735: #
1.324 albertel 1736: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.88 www 1737: my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
1738: $apath=&Apache::lonnet::escape($apath);
1739: $apath=~s/\W/\_/gs;
1740: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1741: }
1742: }
1.44 ng 1743:
1.257 albertel 1744: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1745: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1746: my $mode;
1.257 albertel 1747: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1748: $mode='both';
1.257 albertel 1749: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1750: $mode='text';
1.257 albertel 1751: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1752: $mode='answer';
1753: }
1.329 albertel 1754: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1755: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1756: }
1.144 albertel 1757:
1.257 albertel 1758: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1759: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1760:
1.44 ng 1761: # Display student info
1.41 ng 1762: $request->print(($counter == 0 ? '' : '<br />'));
1.326 albertel 1763: my $result='<table border="0" width="100%"><tr><td bgcolor="#777777">'."\n".
1764: '<table border="0" width="100%"><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1765:
1.257 albertel 1766: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1767: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1768: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1769:
1.118 ng 1770: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1771: my @col_fullnames;
1.56 matthew 1772: my ($classlist,$fullname);
1.257 albertel 1773: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1774: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1775: for (keys (%$handgrade)) {
1.44 ng 1776: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1777: '.maxcollaborators',
1778: $symb,$udom,$uname);
1779: next if ($ncol <= 0);
1780: s/\_/\./g;
1781: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1782: my @goodcollaborators = ();
1783: my @badcollaborators = ();
1784: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1785: $_ =~ s/[\$\^\(\)]//g;
1786: next if ($_ eq '');
1.80 ng 1787: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1788: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1789: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1790: # Doing this grep allows 'fuzzy' specification
1791: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1792: if (! scalar(@Matches)) {
1793: push @badcollaborators,$_;
1794: } else {
1795: push @goodcollaborators, @Matches;
1796: }
1.80 ng 1797: }
1.86 ng 1798: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1799: $result.='<b>Collaborators: </b>';
1.86 ng 1800: foreach (@goodcollaborators) {
1801: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1802: push @col_fullnames, $givenn.' '.$lastname;
1803: $result.=$$fullname{$_}.' ';
1804: }
1.57 matthew 1805: $result.='<br />'."\n";
1.150 albertel 1806: my ($part)=split(/\./,$_);
1.86 ng 1807: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1808: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1809: "\n";
1.86 ng 1810: }
1811: if (scalar(@badcollaborators) > 0) {
1812: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1813: $result.='This student has submitted ';
1814: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1815: $result .= ': '.join(', ',@badcollaborators);
1816: $result .= '</td></tr></table>';
1817: }
1818: if (scalar(@badcollaborators > $ncol)) {
1819: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1820: $result .= 'This student has submitted too many '.
1821: 'collaborators. Maximum is '.$ncol.'.';
1822: $result .= '</td></tr></table>';
1823: }
1.41 ng 1824: }
1825: }
1.44 ng 1826: $request->print($result."\n");
1.33 ng 1827:
1.44 ng 1828: # print student answer/submission
1829: # Options are (1) Handgaded submission only
1830: # (2) Last submission, includes submission that is not handgraded
1831: # (for multi-response type part)
1832: # (3) Last submission plus the parts info
1833: # (4) The whole record for this student
1.257 albertel 1834: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1835: my ($string,$timestamp)= &get_last_submission(\%record);
1836: my $lastsubonly=''.
1837: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1838: $$timestamp)."</td></tr>\n";
1839: if ($$timestamp eq '') {
1840: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1841: } else {
1842: my %seenparts;
1843: for my $part (sort keys(%$handgrade)) {
1844: my ($partid,$respid) = split(/_/,$part);
1.324 albertel 1845: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 1846: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1847: if (exists($seenparts{$partid})) { next; }
1848: $seenparts{$partid}=1;
1.207 albertel 1849: my $submitby='<b>Part:</b> '.$display_part.
1850: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1851: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1852: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1853: '\')"; TARGET=_self>'.
1.257 albertel 1854: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1855: $request->print($submitby);
1856: next;
1857: }
1858: my $responsetype = $responseType->{$partid}->{$respid};
1859: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1860: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1861: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1862: ' )</font> '.
1863: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1864: next;
1865: }
1866: foreach (@$string) {
1867: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1868: if ($part ne ($partid.'_'.$respid)) { next; }
1869: my ($ressub,$subval) = split(/:/,$_,2);
1870: # Similarity check
1871: my $similar='';
1.257 albertel 1872: if($env{'form.checkPlag'}){
1.151 albertel 1873: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1874: &most_similar($uname,$udom,$subval);
1875: if ($osim) {
1876: $osim=int($osim*100.0);
1877: $similar="<hr /><h3><font color=\"#FF0000\">Essay".
1878: " is $osim% similar to an essay by ".
1879: &Apache::loncommon::plainname($oname,$odom).
1880: '</font></h3><blockquote><i>'.
1881: &keywords_highlight($oessay).
1882: '</i></blockquote><hr />';
1883: }
1.150 albertel 1884: }
1.151 albertel 1885: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1886: if ($env{'form.lastSub'} eq 'lastonly' ||
1887: ($env{'form.lastSub'} eq 'hdgrade' &&
1.151 albertel 1888: $$handgrade{$part} eq 'yes')) {
1.324 albertel 1889: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 1890: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1891: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1892: ' )</font> ';
1.313 banghart 1893: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1894: if (@$files) {
1.232 albertel 1895: $lastsubonly.='<br /><font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.303 banghart 1896: my $file_counter = 0;
1.313 banghart 1897: foreach my $file (@$files) {
1.303 banghart 1898: $file_counter ++;
1.232 albertel 1899: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 1900: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 1901: }
1.236 albertel 1902: $lastsubonly.='<br />';
1.41 ng 1903: }
1.151 albertel 1904: $lastsubonly.='<b>Submitted Answer: </b>'.
1905: &cleanRecord($subval,$responsetype,$symb,$partid,
1906: $respid,\%record,$order);
1907: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1908: }
1909: }
1910: }
1.151 albertel 1911: }
1912: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1913: $request->print($lastsubonly);
1.257 albertel 1914: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 1915: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 1916: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1917: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1918: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1919: $env{'request.course.id'},
1.44 ng 1920: $last,'.submission',
1921: 'Apache::grades::keywords_highlight'));
1.41 ng 1922: }
1.120 ng 1923:
1.121 ng 1924: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1925: .$udom.'" />'."\n");
1.41 ng 1926:
1.44 ng 1927: # return if view submission with no grading option
1.257 albertel 1928: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 1929: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 1930: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1931: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 1932: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 1933: if (($env{'form.command'} eq 'submission') ||
1934: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 1935: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 1936: }
1.180 albertel 1937: $request->print($toGrade);
1.41 ng 1938: return;
1.180 albertel 1939: } else {
1940: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 1941: }
1.33 ng 1942:
1.121 ng 1943: # essay grading message center
1.257 albertel 1944: if ($env{'form.handgrade'} eq 'yes') {
1945: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 1946: my $msgfor = $givenn.' '.$lastname;
1947: if (scalar(@col_fullnames) > 0) {
1948: my $lastone = pop @col_fullnames;
1949: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1950: }
1951: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 1952: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1953: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
1954: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 1955: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.298 www 1956: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> ('.
1957: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" />)'.
1.118 ng 1958: '<img src="'.$request->dir_config('lonIconsURL').
1959: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 1960: '<br /> ('.
1961: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 1962: $request->print($result);
1.118 ng 1963: }
1.300 albertel 1964: if ($perm{'vgr'}) {
1.297 www 1965: $request->print('<br />'.
1.300 albertel 1966: &Apache::loncommon::track_student_link(&mt('View recent activity'),
1967: $uname,$udom,'check'));
1.297 www 1968: }
1.300 albertel 1969: if ($perm{'opa'}) {
1.297 www 1970: $request->print('<br />'.
1.300 albertel 1971: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
1972: $uname,$udom,$symb,'check'));
1.297 www 1973: }
1.41 ng 1974:
1975: my %seen = ();
1976: my @partlist;
1.129 ng 1977: my @gradePartRespid;
1.322 albertel 1978: for my $part_resp (sort(keys(%$handgrade))) {
1.317 banghart 1979: my ($partid,$respid) = split(/_/, $part_resp);
1.322 albertel 1980: next if ($seen{$partid} > 0);
1.41 ng 1981: $seen{$partid}++;
1.317 banghart 1982: next if ($$handgrade{$part_resp} =~ /:no$/ && $env{'form.lastSub'} =~ /^(hdgrade)$/);
1.41 ng 1983: push @partlist,$partid;
1.129 ng 1984: push @gradePartRespid,$partid.'.'.$respid;
1.322 albertel 1985: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 1986: }
1.45 ng 1987: $result='<input type="hidden" name="partlist'.$counter.
1988: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 1989: $result.='<input type="hidden" name="gradePartRespid'.
1990: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 1991: my $ctr = 0;
1992: while ($ctr < scalar(@partlist)) {
1993: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1994: $partlist[$ctr].'" />'."\n";
1995: $ctr++;
1996: }
1997: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1998:
1999: # print end of form
2000: if ($counter == $total) {
1.297 www 2001: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 2002: $endform.='<input type="button" value="Save & Next" '.
2003: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
2004: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
2005: my $ntstu ='<select name="NTSTU">'.
2006: '<option>1</option><option>2</option>'.
2007: '<option>3</option><option>5</option>'.
2008: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2009: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 2010: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
2011: $endform.=$ntstu.'student(s) ';
1.126 ng 2012: $endform.='<input type="button" value="Previous" '.
2013: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
2014: '<input type="button" value="Next" '.
2015: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
2016: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.349 ! albertel 2017: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2018: "' name='increment' />";
1.45 ng 2019: $endform.='</td><tr></table></form>';
1.324 albertel 2020: $endform.=&show_grading_menu_form($symb);
1.41 ng 2021: $request->print($endform);
2022: }
2023: return '';
1.38 ng 2024: }
2025:
1.44 ng 2026: #--- Retrieve the last submission for all the parts
1.38 ng 2027: sub get_last_submission {
1.119 ng 2028: my ($returnhash)=@_;
1.46 ng 2029: my (@string,$timestamp);
1.119 ng 2030: if ($$returnhash{'version'}) {
1.46 ng 2031: my %lasthash=();
2032: my ($version);
1.119 ng 2033: for ($version=1;$version<=$$returnhash{'version'};$version++) {
2034: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
2035: $lasthash{$_}=$$returnhash{$version.':'.$_};
2036: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2037: }
2038: }
2039: foreach ((keys %lasthash)) {
2040: if ($_ =~ /\.submission$/) {
2041: my ($partid,$foo) = split(/submission$/,$_);
2042: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
2043: '<font color="red">Draft Copy</font> ' : '';
2044: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 2045: }
2046: }
2047: }
1.125 ng 2048: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 2049: return \@string,\$timestamp;
1.38 ng 2050: }
1.35 ng 2051:
1.44 ng 2052: #--- High light keywords, with style choosen by user.
1.38 ng 2053: sub keywords_highlight {
1.44 ng 2054: my $string = shift;
1.257 albertel 2055: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2056: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2057: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2058: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.41 ng 2059: foreach (@keylist) {
1.257 albertel 2060: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 2061: }
2062: return $string;
1.38 ng 2063: }
1.36 ng 2064:
1.44 ng 2065: #--- Called from submission routine
1.38 ng 2066: sub processHandGrade {
1.41 ng 2067: my ($request) = shift;
1.324 albertel 2068: my $symb = &get_symb($request);
2069: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2070: my $button = $env{'form.gradeOpt'};
2071: my $ngrade = $env{'form.NCT'};
2072: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2073: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2074: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2075:
1.44 ng 2076: if ($button eq 'Save & Next') {
2077: my $ctr = 0;
2078: while ($ctr < $ngrade) {
1.257 albertel 2079: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2080: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2081: if ($errorflag eq 'no_score') {
2082: $ctr++;
2083: next;
2084: }
1.104 albertel 2085: if ($errorflag eq 'not_allowed') {
2086: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
2087: $ctr++;
2088: next;
2089: }
1.257 albertel 2090: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2091: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 2092: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2093: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2094: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.44 ng 2095: my (@msgnum) = split(/,/,$includemsg);
2096: foreach (@msgnum) {
1.257 albertel 2097: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2098: }
1.80 ng 2099: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2100: if ($env{'form.withgrades'.$ctr}) {
2101: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
2102: $message.=" for <a href=\"".
1.80 ng 2103: &Apache::lonnet::clutter($url).
1.257 albertel 2104: "?symb=$symb\">$env{'form.probTitle'}</a>";
1.298 www 2105: }
1.324 albertel 2106: $msgstatus = &Apache::lonmsg::user_normal_msg($uname,$udom,
2107: $subject.' ['.
2108: &Apache::lonnet::declutter($url).']',$message);
1.296 www 2109: $request->print('<br />'.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '.
2110: $msgstatus);
1.44 ng 2111: }
1.257 albertel 2112: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2113: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2114: foreach my $collabstr (@collabstrs) {
2115: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2116: foreach my $collaborator (@collaborators) {
1.150 albertel 2117: my ($errorflag,$pts,$wgt) =
1.324 albertel 2118: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2119: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2120: if ($errorflag eq 'not_allowed') {
1.310 banghart 2121: $request->print("<font color=\"red\">Not allowed to modify grades for $collaborator:$udom</font>");
1.150 albertel 2122: next;
2123: } else {
2124: if ($message ne '') {
1.310 banghart 2125: $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$env{'form.msgsub'},$message);
1.150 albertel 2126: }
1.104 albertel 2127: }
1.44 ng 2128: }
2129: }
2130: }
2131: $ctr++;
2132: }
2133: }
2134:
1.257 albertel 2135: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2136: # Keywords sorted in alphabatical order
1.257 albertel 2137: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2138: my %keyhash = ();
1.257 albertel 2139: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2140: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2141: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2142: $env{'form.keywords'} = join(' ',@keywords);
2143: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2144: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2145: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2146: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2147: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2148:
2149: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2150: # New messages are saved in env for the next student.
1.119 ng 2151: # All messages are saved in nohist_handgrade.db
2152: my ($ctr,$idx) = (1,1);
1.257 albertel 2153: while ($ctr <= $env{'form.savemsgN'}) {
2154: if ($env{'form.savemsg'.$ctr} ne '') {
2155: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2156: $idx++;
2157: }
2158: $ctr++;
1.41 ng 2159: }
1.119 ng 2160: $ctr = 0;
2161: while ($ctr < $ngrade) {
1.257 albertel 2162: if ($env{'form.newmsg'.$ctr} ne '') {
2163: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2164: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2165: $idx++;
2166: }
2167: $ctr++;
1.41 ng 2168: }
1.257 albertel 2169: $env{'form.savemsgN'} = --$idx;
2170: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2171: my $putresult = &Apache::lonnet::put
1.301 albertel 2172: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2173: }
1.44 ng 2174: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2175: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2176: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2177: my ($ctr,$total) = (0,0);
2178: while ($ctr < $ngrade) {
1.257 albertel 2179: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2180: $ctr++;
2181: }
1.257 albertel 2182: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2183: $ctr = 0;
2184: while ($ctr < $total) {
1.257 albertel 2185: my $processUser = $env{'form.unamedom'.$ctr};
2186: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2187: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2188: &submission($request,$ctr,$total-1);
1.41 ng 2189: $ctr++;
2190: }
2191: return '';
2192: }
1.36 ng 2193:
1.121 ng 2194: # Go directly to grade student - from submission or link from chart page
1.120 ng 2195: if ($button eq 'Grade Student') {
1.324 albertel 2196: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2197: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2198: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2199: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2200: &submission($request,0,0);
2201: return '';
2202: }
2203:
1.44 ng 2204: # Get the next/previous one or group of students
1.257 albertel 2205: my $firststu = $env{'form.unamedom0'};
2206: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2207: my $ctr = 2;
1.41 ng 2208: while ($laststu eq '') {
1.257 albertel 2209: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2210: $ctr++;
2211: $laststu = $firststu if ($ctr > $ngrade);
2212: }
1.44 ng 2213:
1.41 ng 2214: my (@parsedlist,@nextlist);
2215: my ($nextflg) = 0;
1.294 albertel 2216: foreach (sort
2217: {
2218: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2219: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2220: }
2221: return $a cmp $b;
2222: } (keys(%$fullname))) {
1.41 ng 2223: if ($nextflg == 1 && $button =~ /Next$/) {
2224: push @parsedlist,$_;
2225: }
2226: $nextflg = 1 if ($_ eq $laststu);
2227: if ($button eq 'Previous') {
2228: last if ($_ eq $firststu);
2229: push @parsedlist,$_;
2230: }
2231: }
2232: $ctr = 0;
2233: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2234: my ($partlist) = &response_type($symb);
1.41 ng 2235: foreach my $student (@parsedlist) {
1.257 albertel 2236: my $submitonly=$env{'form.submitonly'};
1.41 ng 2237: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2238:
2239: if ($submitonly eq 'queued') {
2240: my %queue_status =
2241: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2242: $udom,$uname);
2243: next if (!defined($queue_status{'gradingqueue'}));
2244: }
2245:
1.156 albertel 2246: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2247: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2248: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2249: my $submitted = 0;
1.248 albertel 2250: my $ungraded = 0;
2251: my $incorrect = 0;
1.145 albertel 2252: foreach (keys(%status)) {
2253: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2254: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2255: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2256: my ($foo,$partid,$foo1) = split(/\./,$_);
2257: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2258: $submitted = 0;
2259: }
1.41 ng 2260: }
1.156 albertel 2261: next if (!$submitted && ($submitonly eq 'yes' ||
2262: $submitonly eq 'incorrect' ||
2263: $submitonly eq 'graded'));
1.248 albertel 2264: next if (!$ungraded && ($submitonly eq 'graded'));
2265: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2266: }
2267: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2268: last if ($ctr == $ntstu);
1.41 ng 2269: $ctr++;
2270: }
1.36 ng 2271:
1.41 ng 2272: $ctr = 0;
2273: my $total = scalar(@nextlist)-1;
1.39 ng 2274:
1.41 ng 2275: foreach (sort @nextlist) {
2276: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2277: $env{'form.student'} = $uname;
2278: $env{'form.userdom'} = $udom;
2279: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2280: &submission($request,$ctr,$total);
2281: $ctr++;
2282: }
2283: if ($total < 0) {
2284: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
2285: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2286: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.324 albertel 2287: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2288: $request->print($the_end);
2289: }
2290: return '';
1.38 ng 2291: }
1.36 ng 2292:
1.44 ng 2293: #---- Save the score and award for each student, if changed
1.38 ng 2294: sub saveHandGrade {
1.324 albertel 2295: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2296: my @version_parts;
1.104 albertel 2297: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2298: $env{'request.course.id'});
1.104 albertel 2299: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2300: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2301: my @parts_graded;
1.77 ng 2302: my %newrecord = ();
2303: my ($pts,$wgt) = ('','');
1.269 raeburn 2304: my %aggregate = ();
2305: my $aggregateflag = 0;
1.301 albertel 2306: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2307: foreach my $new_part (@parts) {
1.337 banghart 2308: #collaborator ($submi may vary for different parts
1.259 banghart 2309: if ($submitter && $new_part ne $part) { next; }
2310: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2311: if ($dropMenu eq 'excused') {
1.259 banghart 2312: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2313: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2314: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2315: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2316: }
1.259 banghart 2317: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2318: }
1.125 ng 2319: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2320: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2321: foreach my $key (keys (%record)) {
1.259 banghart 2322: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2323: }
1.259 banghart 2324: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2325: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2326: my $totaltries = $record{'resource.'.$part.'.tries'};
2327:
2328: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2329: [$new_part]);
2330: my $aggtries =$totaltries;
1.269 raeburn 2331: if ($last_resets{$new_part}) {
1.270 albertel 2332: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2333: $new_part);
1.269 raeburn 2334: }
1.270 albertel 2335:
2336: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2337: if ($aggtries > 0) {
1.327 albertel 2338: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2339: $aggregateflag = 1;
2340: }
1.125 ng 2341: } elsif ($dropMenu eq '') {
1.259 banghart 2342: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2343: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2344: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2345: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2346: next;
2347: }
1.259 banghart 2348: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2349: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2350: my $partial= $pts/$wgt;
1.259 banghart 2351: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2352: #do not update score for part if not changed.
1.346 banghart 2353: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2354: next;
1.251 banghart 2355: } else {
1.259 banghart 2356: push @parts_graded, $new_part;
1.153 albertel 2357: }
1.259 banghart 2358: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2359: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2360: }
1.259 banghart 2361: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2362: if ($partial == 0) {
1.153 albertel 2363: if ($record{$reckey} ne 'incorrect_by_override') {
2364: $newrecord{$reckey} = 'incorrect_by_override';
2365: }
1.41 ng 2366: } else {
1.153 albertel 2367: if ($record{$reckey} ne 'correct_by_override') {
2368: $newrecord{$reckey} = 'correct_by_override';
2369: }
2370: }
2371: if ($submitter &&
1.259 banghart 2372: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2373: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2374: }
1.259 banghart 2375: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2376: "$env{'user.name'}:$env{'user.domain'}";
1.337 banghart 2377: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.41 ng 2378: }
1.259 banghart 2379: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2380: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2381: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2382: $dropMenu eq 'reset status')
2383: {
1.342 banghart 2384: push (@version_parts,$new_part);
1.259 banghart 2385: }
1.41 ng 2386: }
1.301 albertel 2387: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2388: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2389:
1.344 albertel 2390: if (%newrecord) {
2391: if (@version_parts) {
1.343 banghart 2392: my @changed_keys = &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2393: @newrecord{@changed_keys} = @record{@changed_keys};
1.259 banghart 2394: }
1.44 ng 2395: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2396: $env{'request.course.id'},$domain,$stuname);
1.301 albertel 2397: my @ungraded_parts;
2398: foreach my $part (@parts) {
2399: if ( !defined($record{'resource.'.$part.'.awarded'})
2400: && !defined($newrecord{'resource.'.$part.'.awarded'}) ) {
2401: push(@ungraded_parts, $part);
2402: }
2403: }
2404: if ( !@ungraded_parts ) {
2405: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2406: $cnum,$domain,$stuname);
2407: }
1.41 ng 2408: }
1.269 raeburn 2409: if ($aggregateflag) {
2410: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2411: $cdom,$cnum);
1.269 raeburn 2412: }
1.301 albertel 2413: return ('',$pts,$wgt);
1.36 ng 2414: }
1.322 albertel 2415:
1.337 banghart 2416: sub handback_files {
2417: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.338 banghart 2418: my $portfolio_root = &Apache::loncommon::propath($domain,
2419: $stuname).
2420: '/userfiles/portfolio';
1.337 banghart 2421: my ($partlist,$handgrade,$responseType) = &response_type($symb);
2422: foreach my $part_resp (sort(keys(%$handgrade))) {
2423: my ($part_id, $resp_id) = split(/_/,$part_resp);
2424: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2425: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2426: my $file_counter = 1;
2427: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2428: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2429: my ($directory,$answer_file) =
2430: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2431: my ($answer_name,$answer_ver,$answer_ext) =
2432: &file_name_version_ext($answer_file);
1.341 banghart 2433: $directory =~ /^.+$stuname\/portfolio(.*)/;
2434: my $portfolio_path = $1;
2435: my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
1.338 banghart 2436: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.341 banghart 2437: my $new_answer = &version_selected_portfile($domain, $stuname, $portfolio_path, $answer_file, $version);
1.338 banghart 2438: $$newrecord{"resource.$new_part.$resp_id.handback"} = $new_answer;
1.337 banghart 2439: # set the filename to match the submitted file name
2440: $env{'form.'.$newflg.'_'.$part_resp.'_returndoc1.filename'} = $env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter};
2441: my $result=&Apache::lonnet::userfileupload($newflg.'_'.$part_resp.'_returndoc'.$file_counter,'',
1.338 banghart 2442: 'portfolio',undef,undef,undef,$stuname,$domain);
1.337 banghart 2443: if ($result !~ m|^/uploaded/|) {
2444: $request->print('<font color="red"> An errror occured ('.$result.
2445: ') while trying to upload '.&display_file().'</font><br />');
2446: # $request->print(&done('Back'));
2447: }
2448: $request->print("<br />".$fname." will be the uploaded file name");
1.338 banghart 2449: $request->print("<font color=\"red\">Will upload document </font>".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2450: $file_counter++;
2451: }
2452: }
2453: }
1.338 banghart 2454: return;
1.337 banghart 2455: }
2456:
1.313 banghart 2457: sub get_submitted_files {
2458: my ($udom,$uname,$partid,$respid,$record) = @_;
2459: my @files;
2460: if ($$record{"resource.$partid.$respid.portfiles"}) {
2461: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2462: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2463: push(@files,$file_url.$file);
2464: }
2465: }
2466: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2467: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2468: }
2469: return (\@files);
2470: }
1.322 albertel 2471:
1.269 raeburn 2472: # ----------- Provides number of tries since last reset.
2473: sub get_num_tries {
2474: my ($record,$last_reset,$part) = @_;
2475: my $timestamp = '';
2476: my $num_tries = 0;
2477: if ($$record{'version'}) {
2478: for (my $version=$$record{'version'};$version>=1;$version--) {
2479: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2480: $timestamp = $$record{$version.':timestamp'};
2481: if ($timestamp > $last_reset) {
2482: $num_tries ++;
2483: } else {
2484: last;
2485: }
2486: }
2487: }
2488: }
2489: return $num_tries;
2490: }
2491:
2492: # ----------- Determine decrements required in aggregate totals
2493: sub decrement_aggs {
2494: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2495: my %decrement = (
2496: attempts => 0,
2497: users => 0,
2498: correct => 0
2499: );
2500: $decrement{'attempts'} = $aggtries;
2501: if ($solvedstatus =~ /^correct/) {
2502: $decrement{'correct'} = 1;
2503: }
2504: if ($aggtries == $totaltries) {
2505: $decrement{'users'} = 1;
2506: }
2507: foreach my $type (keys (%decrement)) {
2508: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2509: }
2510: return;
2511: }
2512:
2513: # ----------- Determine timestamps for last reset of aggregate totals for parts
2514: sub get_last_resets {
1.270 albertel 2515: my ($symb,$courseid,$partids) =@_;
2516: my %last_resets;
1.269 raeburn 2517: my $cdom = $env{'course.'.$courseid.'.domain'};
2518: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2519: my @keys;
2520: foreach my $part (@{$partids}) {
2521: push(@keys,"$symb\0$part\0resettime");
2522: }
2523: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2524: $cdom,$cname);
2525: foreach my $part (@{$partids}) {
2526: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2527: }
1.270 albertel 2528: return %last_resets;
1.269 raeburn 2529: }
2530:
1.251 banghart 2531: # ----------- Handles creating versions for portfolio files as answers
2532: sub version_portfiles {
1.343 banghart 2533: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2534: my $version_parts = join('|',@$v_flag);
1.343 banghart 2535: my @returned_keys;
1.255 banghart 2536: my $parts = join('|', @$parts_graded);
1.252 banghart 2537: my $portfolio_root = &Apache::loncommon::propath($domain,
1.306 banghart 2538: $stu_name).
1.252 banghart 2539: '/userfiles/portfolio';
1.277 albertel 2540: foreach my $key (keys(%$record)) {
1.259 banghart 2541: my $new_portfiles;
1.263 banghart 2542: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2543: my @versioned_portfiles;
1.255 banghart 2544: my @portfiles = split(/,/,$$record{$key});
1.252 banghart 2545: foreach my $file (@portfiles) {
1.306 banghart 2546: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2547: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2548: my ($answer_name,$answer_ver,$answer_ext) =
2549: &file_name_version_ext($answer_file);
1.306 banghart 2550: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.342 banghart 2551: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2552: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2553: if ($new_answer ne 'problem getting file') {
1.342 banghart 2554: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2555: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
2556: ['/portfolio'.$directory.$new_answer],
2557: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2558: }
1.252 banghart 2559: }
1.343 banghart 2560: $$record{$key} = join(',',@versioned_portfiles);
2561: push(@returned_keys,$key);
1.251 banghart 2562: }
2563: }
1.343 banghart 2564: return (@returned_keys);
1.305 banghart 2565: }
2566:
1.307 banghart 2567: sub get_next_version {
1.341 banghart 2568: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2569: my $version;
2570: foreach my $row (@$dir_list) {
2571: my ($file) = split(/\&/,$row,2);
2572: my ($file_name,$file_version,$file_ext) =
2573: &file_name_version_ext($file);
2574: if (($file_name eq $answer_name) &&
2575: ($file_ext eq $answer_ext)) {
2576: # gets here if filename and extension match, regardless of version
2577: if ($file_version ne '') {
2578: # a versioned file is found so save it for later
2579: if ($file_version > $version) {
2580: $version = $file_version;
2581: }
2582: }
2583: }
2584: }
2585: $version ++;
2586: return($version);
2587: }
2588:
1.305 banghart 2589: sub version_selected_portfile {
1.306 banghart 2590: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2591: my ($answer_name,$answer_ver,$answer_ext) =
2592: &file_name_version_ext($file_name);
2593: my $new_answer;
2594: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2595: if($env{'form.copy'} eq '-1') {
2596: &Apache::lonnet::logthis('problem getting file '.$file_name);
2597: $new_answer = 'problem getting file';
2598: } else {
2599: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2600: my $copy_result = &Apache::lonnet::finishuserfileupload(
2601: $stu_name,$domain,'copy',
2602: '/portfolio'.$directory.$new_answer);
2603: }
2604: return ($new_answer);
1.251 banghart 2605: }
2606:
1.304 albertel 2607: sub file_name_version_ext {
2608: my ($file)=@_;
2609: my @file_parts = split(/\./, $file);
2610: my ($name,$version,$ext);
2611: if (@file_parts > 1) {
2612: $ext=pop(@file_parts);
2613: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2614: $version=pop(@file_parts);
2615: }
2616: $name=join('.',@file_parts);
2617: } else {
2618: $name=join('.',@file_parts);
2619: }
2620: return($name,$version,$ext);
2621: }
2622:
1.44 ng 2623: #--------------------------------------------------------------------------------------
2624: #
2625: #-------------------------- Next few routines handles grading by section or whole class
2626: #
2627: #--- Javascript to handle grading by section or whole class
1.42 ng 2628: sub viewgrades_js {
2629: my ($request) = shift;
2630:
1.41 ng 2631: $request->print(<<VIEWJAVASCRIPT);
2632: <script type="text/javascript" language="javascript">
1.45 ng 2633: function writePoint(partid,weight,point) {
1.125 ng 2634: var radioButton = document.classgrade["RADVAL_"+partid];
2635: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2636: if (point == "textval") {
1.125 ng 2637: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2638: if (isNaN(point) || parseFloat(point) < 0) {
2639: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2640: var resetbox = false;
2641: for (var i=0; i<radioButton.length; i++) {
2642: if (radioButton[i].checked) {
2643: textbox.value = i;
2644: resetbox = true;
2645: }
2646: }
2647: if (!resetbox) {
2648: textbox.value = "";
2649: }
2650: return;
2651: }
1.109 matthew 2652: if (parseFloat(point) > parseFloat(weight)) {
2653: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2654: ") greater than the weight for the part. Accept?");
2655: if (resp == false) {
2656: textbox.value = "";
2657: return;
2658: }
2659: }
1.42 ng 2660: for (var i=0; i<radioButton.length; i++) {
2661: radioButton[i].checked=false;
1.109 matthew 2662: if (parseFloat(point) == i) {
1.42 ng 2663: radioButton[i].checked=true;
2664: }
2665: }
1.41 ng 2666:
1.42 ng 2667: } else {
1.125 ng 2668: textbox.value = parseFloat(point);
1.42 ng 2669: }
1.41 ng 2670: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2671: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2672: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2673: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2674: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2675: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2676: if (saveval != "correct") {
2677: scorename.value = point;
1.43 ng 2678: if (selname[0].selected != true) {
2679: selname[0].selected = true;
2680: }
1.42 ng 2681: }
2682: }
1.125 ng 2683: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2684: }
2685:
2686: function writeRadText(partid,weight) {
1.125 ng 2687: var selval = document.classgrade["SELVAL_"+partid];
2688: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2689: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2690: var textbox = document.classgrade["TEXTVAL_"+partid];
2691: if (selval[1].selected || selval[2].selected) {
1.42 ng 2692: for (var i=0; i<radioButton.length; i++) {
2693: radioButton[i].checked=false;
2694:
2695: }
2696: textbox.value = "";
2697:
2698: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2699: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2700: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2701: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2702: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2703: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2704: if ((saveval != "correct") || override) {
1.42 ng 2705: scorename.value = "";
1.125 ng 2706: if (selval[1].selected) {
2707: selname[1].selected = true;
2708: } else {
2709: selname[2].selected = true;
2710: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2711: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2712: }
1.42 ng 2713: }
2714: }
1.43 ng 2715: } else {
2716: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2717: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2718: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2719: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2720: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2721: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2722: if ((saveval != "correct") || override) {
1.125 ng 2723: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2724: selname[0].selected = true;
2725: }
2726: }
2727: }
1.42 ng 2728: }
2729:
2730: function changeSelect(partid,user) {
1.125 ng 2731: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2732: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2733: var point = textbox.value;
1.125 ng 2734: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2735:
1.109 matthew 2736: if (isNaN(point) || parseFloat(point) < 0) {
2737: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2738: textbox.value = "";
2739: return;
2740: }
1.109 matthew 2741: if (parseFloat(point) > parseFloat(weight)) {
2742: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2743: ") greater than the weight of the part. Accept?");
2744: if (resp == false) {
2745: textbox.value = "";
2746: return;
2747: }
2748: }
1.42 ng 2749: selval[0].selected = true;
2750: }
2751:
2752: function changeOneScore(partid,user) {
1.125 ng 2753: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2754: if (selval[1].selected || selval[2].selected) {
2755: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2756: if (selval[2].selected) {
2757: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2758: }
1.269 raeburn 2759: }
1.42 ng 2760: }
2761:
2762: function resetEntry(numpart) {
2763: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2764: var partid = document.classgrade["partid_"+ctpart].value;
2765: var radioButton = document.classgrade["RADVAL_"+partid];
2766: var textbox = document.classgrade["TEXTVAL_"+partid];
2767: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2768: for (var i=0; i<radioButton.length; i++) {
2769: radioButton[i].checked=false;
2770:
2771: }
2772: textbox.value = "";
2773: selval[0].selected = true;
2774:
2775: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2776: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2777: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2778: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2779: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2780: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2781: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2782: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2783: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2784: if (saveselval == "excused") {
1.43 ng 2785: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2786: } else {
1.43 ng 2787: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2788: }
2789: }
1.41 ng 2790: }
1.42 ng 2791: }
2792:
1.41 ng 2793: </script>
2794: VIEWJAVASCRIPT
1.42 ng 2795: }
2796:
1.44 ng 2797: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2798: sub viewgrades {
2799: my ($request) = shift;
2800: &viewgrades_js($request);
1.41 ng 2801:
1.324 albertel 2802: my ($symb) = &get_symb($request);
1.168 albertel 2803: #need to make sure we have the correct data for later EXT calls,
2804: #thus invalidate the cache
2805: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2806: $env{'course.'.$env{'request.course.id'}.'.num'},
2807: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2808: &Apache::lonnet::clear_EXT_cache_status();
2809:
1.167 sakharuk 2810: my $result='<h3><font color="#339933">'.&mt('Manual Grading').'</font></h3>';
1.257 albertel 2811: $result.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n";
1.41 ng 2812:
2813: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 2814: $result.=&jscriptNform($symb);
1.41 ng 2815:
1.44 ng 2816: #beginning of class grading form
1.41 ng 2817: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2818: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.38 ng 2819: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2820: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2821: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2822: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2823: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2824:
1.126 ng 2825: my $sectionClass;
1.257 albertel 2826: if ($env{'form.section'} eq 'all') {
1.126 ng 2827: $sectionClass='Class </h3>';
1.257 albertel 2828: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2829: $sectionClass='Students in no Section </h3>';
1.52 albertel 2830: } else {
1.257 albertel 2831: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2832: }
1.126 ng 2833: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2834: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2835: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2836: #radio buttons/text box for assigning points for a section or class.
2837: #handles different parts of a problem
1.324 albertel 2838: my ($partlist,$handgrade) = &response_type($symb);
1.42 ng 2839: my %weight = ();
2840: my $ctsparts = 0;
1.41 ng 2841: $result.='<table border="0">';
1.45 ng 2842: my %seen = ();
1.42 ng 2843: for (sort keys(%$handgrade)) {
1.54 albertel 2844: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 2845: next if $seen{$partid};
2846: $seen{$partid}++;
1.147 albertel 2847: my $handgrade=$$handgrade{$_};
1.42 ng 2848: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2849: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2850:
1.44 ng 2851: $result.='<input type="hidden" name="partid_'.
2852: $ctsparts.'" value="'.$partid.'" />'."\n";
2853: $result.='<input type="hidden" name="weight_'.
2854: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.324 albertel 2855: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 2856: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 2857: $result.='<table border="0"><tr>';
1.41 ng 2858: my $ctr = 0;
1.42 ng 2859: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 2860: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 2861: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 2862: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 2863: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
2864: $ctr++;
2865: }
2866: $result.='</tr></table>';
1.44 ng 2867: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 2868: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
2869: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 2870: $weight{$partid}.' (problem weight)</td>'."\n";
2871: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 2872: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 2873: $weight{$partid}.')"> '.
1.42 ng 2874: '<option selected="on"> </option>'.
1.125 ng 2875: '<option>excused</option>'.
1.265 www 2876: '<option>reset status</option></select></td>'.
1.266 albertel 2877: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 2878: $ctsparts++;
1.41 ng 2879: }
1.52 albertel 2880: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
2881: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 2882: $result.='<input type="button" value="Reset" '.
1.111 ng 2883: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 2884:
1.44 ng 2885: #table listing all the students in a section/class
2886: #header of table
1.126 ng 2887: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 2888: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 2889: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 2890: '<td>'.&nameUserString('header')."</td>\n";
1.324 albertel 2891: my (@parts) = sort(&getpartlist($symb));
2892: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 2893: my @partids = ();
1.41 ng 2894: foreach my $part (@parts) {
2895: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 2896: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 2897: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 2898: my ($partid) = &split_part_type($part);
1.269 raeburn 2899: push(@partids, $partid);
1.324 albertel 2900: my $display_part=&get_display_part($partid,$symb);
1.41 ng 2901: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 2902: $result.='<td><b>Score Part:</b> '.$display_part.
2903: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 2904: next;
1.207 albertel 2905: } else {
2906: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 2907: }
1.53 albertel 2908: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 2909: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 2910: }
2911: $result.='</tr>';
1.44 ng 2912:
1.270 albertel 2913: my %last_resets =
2914: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 2915:
1.41 ng 2916: #get info for each student
1.44 ng 2917: #list all the students - with points and grade status
1.257 albertel 2918: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 2919: my $ctr = 0;
1.294 albertel 2920: foreach (sort
2921: {
2922: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2923: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2924: }
2925: return $a cmp $b;
2926: } (keys(%$fullname))) {
1.126 ng 2927: $ctr++;
1.324 albertel 2928: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 2929: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 2930: }
2931: $result.='</table></td></tr></table>';
2932: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 2933: $result.='<input type="button" value="Save" '.
1.45 ng 2934: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 2935: if (scalar(%$fullname) eq 0) {
2936: my $colspan=3+scalar(@parts);
1.257 albertel 2937: $result='<font color="red">There are no students in section "'.$env{'form.section'}.
2938: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 2939: }
1.324 albertel 2940: $result.=&show_grading_menu_form($symb);
1.41 ng 2941: return $result;
2942: }
2943:
1.44 ng 2944: #--- call by previous routine to display each student
1.41 ng 2945: sub viewstudentgrade {
1.324 albertel 2946: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 2947: my ($uname,$udom) = split(/:/,$student);
2948: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 2949: my %aggregates = ();
1.233 albertel 2950: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
2951: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
2952: "\n".$ctr.' </td><td> '.
1.44 ng 2953: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 2954: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.257 albertel 2955: '<font color="#999999">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.281 albertel 2956: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 2957: foreach my $apart (@$parts) {
2958: my ($part,$type) = &split_part_type($apart);
1.41 ng 2959: my $score=$record{"resource.$part.$type"};
1.276 albertel 2960: $result.='<td align="center">';
1.269 raeburn 2961: my ($aggtries,$totaltries);
2962: unless (exists($aggregates{$part})) {
1.270 albertel 2963: $totaltries = $record{'resource.'.$part.'.tries'};
2964:
2965: $aggtries = $totaltries;
1.269 raeburn 2966: if ($$last_resets{$part}) {
1.270 albertel 2967: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
2968: $part);
2969: }
1.269 raeburn 2970: $result.='<input type="hidden" name="'.
2971: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
2972: $result.='<input type="hidden" name="'.
2973: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
2974: $aggregates{$part} = 1;
2975: }
1.41 ng 2976: if ($type eq 'awarded') {
1.320 albertel 2977: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 2978: $result.='<input type="hidden" name="'.
1.89 albertel 2979: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 2980: $result.='<input type="text" name="'.
1.89 albertel 2981: 'GD_'.$student.'_'.$part.'_awarded" '.
2982: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 2983: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 2984: } elsif ($type eq 'solved') {
2985: my ($status,$foo)=split(/_/,$score,2);
2986: $status = 'nothing' if ($status eq '');
1.89 albertel 2987: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 2988: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 2989: $result.=' <select name="'.
1.89 albertel 2990: 'GD_'.$student.'_'.$part.'_solved" '.
2991: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 2992: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
2993: : '<option selected="on"> </option><option>excused</option>')."\n";
2994: $result.='<option>reset status</option>';
1.126 ng 2995: $result.="</select> </td>\n";
1.122 ng 2996: } else {
2997: $result.='<input type="hidden" name="'.
2998: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
2999: "\n";
1.233 albertel 3000: $result.='<input type="text" name="'.
1.122 ng 3001: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3002: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3003: }
3004: }
3005: $result.='</tr>';
3006: return $result;
1.38 ng 3007: }
3008:
1.44 ng 3009: #--- change scores for all the students in a section/class
3010: # record does not get update if unchanged
1.38 ng 3011: sub editgrades {
1.41 ng 3012: my ($request) = @_;
3013:
1.324 albertel 3014: my $symb=&get_symb($request);
1.45 ng 3015: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.257 albertel 3016: $title.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font><br />'."\n";
3017: $title.='<font size=+1><b>Section: </b>'.$env{'form.section'}.'</font>'."\n";
1.126 ng 3018:
1.44 ng 3019: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 3020: $result.= '<table border="0"><tr bgcolor="#deffff">'.
3021: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
3022: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 3023:
3024: my %scoreptr = (
3025: 'correct' =>'correct_by_override',
3026: 'incorrect'=>'incorrect_by_override',
3027: 'excused' =>'excused',
3028: 'ungraded' =>'ungraded_attempted',
3029: 'nothing' => '',
3030: );
1.257 albertel 3031: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3032:
1.44 ng 3033: my (@partid);
3034: my %weight = ();
1.54 albertel 3035: my %columns = ();
1.44 ng 3036: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3037:
1.324 albertel 3038: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3039: my $header;
1.257 albertel 3040: while ($ctr < $env{'form.totalparts'}) {
3041: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 3042: push @partid,$partid;
1.257 albertel 3043: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3044: $ctr++;
1.54 albertel 3045: }
1.324 albertel 3046: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3047: foreach my $partid (@partid) {
3048: $header .= '<td align="center"> <b>Old Score</b> </td>'.
3049: '<td align="center"> <b>New Score</b> </td>';
3050: $columns{$partid}=2;
3051: foreach my $stores (@parts) {
3052: my ($part,$type) = &split_part_type($stores);
3053: if ($part !~ m/^\Q$partid\E/) { next;}
3054: if ($type eq 'awarded' || $type eq 'solved') { next; }
3055: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3056: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 3057: $display =~ s/Number of Attempts/Tries/;
3058: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
3059: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 3060: $columns{$partid}+=2;
3061: }
3062: }
3063: foreach my $partid (@partid) {
1.324 albertel 3064: my $display_part=&get_display_part($partid,$symb);
1.54 albertel 3065: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 3066: '" align="center"><b>Part:</b> '.$display_part.
3067: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 3068:
1.44 ng 3069: }
3070: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 3071: $result .= $header;
1.44 ng 3072: $result .= '</tr>'."\n";
1.93 albertel 3073: my $noupdate;
1.126 ng 3074: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3075: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3076: my $line;
1.257 albertel 3077: my $user = $env{'form.ctr'.$i};
1.281 albertel 3078: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3079: my %newrecord;
3080: my $updateflag = 0;
1.281 albertel 3081: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3082: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3083: if (!&canmodify($usec)) {
1.126 ng 3084: my $numcols=scalar(@partid)*4+2;
1.105 albertel 3085: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
3086: next;
3087: }
1.269 raeburn 3088: my %aggregate = ();
3089: my $aggregateflag = 0;
1.281 albertel 3090: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3091: foreach (@partid) {
1.257 albertel 3092: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3093: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3094: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3095: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3096: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3097: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3098: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3099: my $score;
3100: if ($partial eq '') {
1.257 albertel 3101: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3102: } elsif ($partial > 0) {
3103: $score = 'correct_by_override';
3104: } elsif ($partial == 0) {
3105: $score = 'incorrect_by_override';
3106: }
1.257 albertel 3107: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3108: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3109:
1.292 albertel 3110: $newrecord{'resource.'.$_.'.regrader'}=
3111: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3112: if ($dropMenu eq 'reset status' &&
3113: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3114: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3115: $newrecord{'resource.'.$_.'.solved'} = '';
3116: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3117: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3118: $updateflag = 1;
1.269 raeburn 3119: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3120: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3121: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3122: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3123: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3124: $aggregateflag = 1;
3125: }
1.139 albertel 3126: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3127: $updateflag = 1;
3128: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3129: $newrecord{'resource.'.$_.'.solved'} = $score;
3130: $rec_update++;
1.125 ng 3131: }
3132:
1.93 albertel 3133: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3134: '<td align="center">'.$awarded.
3135: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3136:
1.54 albertel 3137:
3138: my $partid=$_;
3139: foreach my $stores (@parts) {
3140: my ($part,$type) = &split_part_type($stores);
3141: if ($part !~ m/^\Q$partid\E/) { next;}
3142: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3143: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3144: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3145: if ($awarded ne '' && $awarded ne $old_aw) {
3146: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3147: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3148: $updateflag=1;
3149: }
1.93 albertel 3150: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3151: '<td align="center">'.$awarded.' </td>';
3152: }
1.44 ng 3153: }
1.93 albertel 3154: $line.='</tr>'."\n";
1.301 albertel 3155:
3156: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3157: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3158:
1.44 ng 3159: if ($updateflag) {
3160: $count++;
1.257 albertel 3161: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3162: $udom,$uname);
1.301 albertel 3163:
3164: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3165: $cnum,$udom,$uname)) {
3166: # need to figure out if should be in queue.
3167: my %record =
3168: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3169: $udom,$uname);
3170: my $all_graded = 1;
3171: my $none_graded = 1;
3172: foreach my $part (@parts) {
3173: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3174: $all_graded = 0;
3175: } else {
3176: $none_graded = 0;
3177: }
3178: }
3179:
3180: if ($all_graded || $none_graded) {
3181: &Apache::bridgetask::remove_from_queue('gradingqueue',
3182: $symb,$cdom,$cnum,
3183: $udom,$uname);
3184: }
3185: }
3186:
1.126 ng 3187: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3188: $updateCtr++;
1.93 albertel 3189: } else {
1.126 ng 3190: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3191: $noupdateCtr++;
1.44 ng 3192: }
1.269 raeburn 3193: if ($aggregateflag) {
3194: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3195: $cdom,$cnum);
1.269 raeburn 3196: }
1.93 albertel 3197: }
3198: if ($noupdate) {
1.126 ng 3199: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3200: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3201: $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 3202: }
1.72 ng 3203: $result .= '</table></td></tr></table>'."\n".
1.324 albertel 3204: &show_grading_menu_form ($symb);
1.125 ng 3205: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3206: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3207: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3208: return $title.$msg.$result;
1.5 albertel 3209: }
1.54 albertel 3210:
3211: sub split_part_type {
3212: my ($partstr) = @_;
3213: my ($temp,@allparts)=split(/_/,$partstr);
3214: my $type=pop(@allparts);
3215: my $part=join('.',@allparts);
3216: return ($part,$type);
3217: }
3218:
1.44 ng 3219: #------------- end of section for handling grading by section/class ---------
3220: #
3221: #----------------------------------------------------------------------------
3222:
1.5 albertel 3223:
1.44 ng 3224: #----------------------------------------------------------------------------
3225: #
3226: #-------------------------- Next few routines handles grading by csv upload
3227: #
3228: #--- Javascript to handle csv upload
1.27 albertel 3229: sub csvupload_javascript_reverse_associate {
1.246 albertel 3230: my $error1=&mt('You need to specify the username or ID');
3231: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3232: return(<<ENDPICK);
3233: function verify(vf) {
3234: var foundsomething=0;
3235: var founduname=0;
1.243 albertel 3236: var foundID=0;
1.27 albertel 3237: for (i=0;i<=vf.nfields.value;i++) {
3238: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3239: if (i==0 && tw!=0) { foundID=1; }
3240: if (i==1 && tw!=0) { founduname=1; }
3241: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3242: }
1.246 albertel 3243: if (founduname==0 && foundID==0) {
3244: alert('$error1');
3245: return;
1.27 albertel 3246: }
3247: if (foundsomething==0) {
1.246 albertel 3248: alert('$error2');
3249: return;
1.27 albertel 3250: }
3251: vf.submit();
3252: }
3253: function flip(vf,tf) {
3254: var nw=eval('vf.f'+tf+'.selectedIndex');
3255: var i;
3256: for (i=0;i<=vf.nfields.value;i++) {
3257: //can not pick the same destination field for both name and domain
3258: if (((i ==0)||(i ==1)) &&
3259: ((tf==0)||(tf==1)) &&
3260: (i!=tf) &&
3261: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3262: eval('vf.f'+i+'.selectedIndex=0;')
3263: }
3264: }
3265: }
3266: ENDPICK
3267: }
3268:
3269: sub csvupload_javascript_forward_associate {
1.246 albertel 3270: my $error1=&mt('You need to specify the username or ID');
3271: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3272: return(<<ENDPICK);
3273: function verify(vf) {
3274: var foundsomething=0;
3275: var founduname=0;
1.243 albertel 3276: var foundID=0;
1.27 albertel 3277: for (i=0;i<=vf.nfields.value;i++) {
3278: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3279: if (tw==1) { foundID=1; }
3280: if (tw==2) { founduname=1; }
3281: if (tw>3) { foundsomething=1; }
1.27 albertel 3282: }
1.246 albertel 3283: if (founduname==0 && foundID==0) {
3284: alert('$error1');
3285: return;
1.27 albertel 3286: }
3287: if (foundsomething==0) {
1.246 albertel 3288: alert('$error2');
3289: return;
1.27 albertel 3290: }
3291: vf.submit();
3292: }
3293: function flip(vf,tf) {
3294: var nw=eval('vf.f'+tf+'.selectedIndex');
3295: var i;
3296: //can not pick the same destination field twice
3297: for (i=0;i<=vf.nfields.value;i++) {
3298: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3299: eval('vf.f'+i+'.selectedIndex=0;')
3300: }
3301: }
3302: }
3303: ENDPICK
3304: }
3305:
1.26 albertel 3306: sub csvuploadmap_header {
1.324 albertel 3307: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3308: my $javascript;
1.257 albertel 3309: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3310: $javascript=&csvupload_javascript_reverse_associate();
3311: } else {
3312: $javascript=&csvupload_javascript_forward_associate();
3313: }
1.45 ng 3314:
1.324 albertel 3315: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3316: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3317: my $ignore=&mt('Ignore First Line');
1.41 ng 3318: $request->print(<<ENDPICK);
1.26 albertel 3319: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 3320: <h3><font color="#339933">Uploading Class Grades</font></h3>
3321: $result
1.326 albertel 3322: <hr />
1.26 albertel 3323: <h3>Identify fields</h3>
3324: Total number of records found in file: $distotal <hr />
3325: Enter as many fields as you can. The system will inform you and bring you back
3326: to this page if the data selected is insufficient to run your class.<hr />
3327: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3328: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3329: <input type="hidden" name="associate" value="" />
3330: <input type="hidden" name="phase" value="three" />
3331: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3332: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3333: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3334: <input type="hidden" name="upfile_associate"
1.257 albertel 3335: value="$env{'form.upfile_associate'}" />
1.26 albertel 3336: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3337: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3338: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3339: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3340: <hr />
3341: <script type="text/javascript" language="Javascript">
3342: $javascript
3343: </script>
3344: ENDPICK
1.118 ng 3345: return '';
1.26 albertel 3346:
3347: }
3348:
3349: sub csvupload_fields {
1.324 albertel 3350: my ($symb) = @_;
3351: my (@parts) = &getpartlist($symb);
1.243 albertel 3352: my @fields=(['ID','Student ID'],
3353: ['username','Student Username'],
3354: ['domain','Student Domain']);
1.324 albertel 3355: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3356: foreach my $part (sort(@parts)) {
3357: my @datum;
3358: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3359: my $name=$part;
3360: if (!$display) { $display = $name; }
3361: @datum=($name,$display);
1.244 albertel 3362: if ($name=~/^stores_(.*)_awarded/) {
3363: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3364: }
1.41 ng 3365: push(@fields,\@datum);
3366: }
3367: return (@fields);
1.26 albertel 3368: }
3369:
3370: sub csvuploadmap_footer {
1.41 ng 3371: my ($request,$i,$keyfields) =@_;
3372: $request->print(<<ENDPICK);
1.26 albertel 3373: </table>
3374: <input type="hidden" name="nfields" value="$i" />
3375: <input type="hidden" name="keyfields" value="$keyfields" />
3376: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3377: </form>
3378: ENDPICK
3379: }
3380:
1.283 albertel 3381: sub checkforfile_js {
1.86 ng 3382: my $result =<<CSVFORMJS;
3383: <script type="text/javascript" language="javascript">
3384: function checkUpload(formname) {
3385: if (formname.upfile.value == "") {
3386: alert("Please use the browse button to select a file from your local directory.");
3387: return false;
3388: }
3389: formname.submit();
3390: }
3391: </script>
3392: CSVFORMJS
1.283 albertel 3393: return $result;
3394: }
3395:
3396: sub upcsvScores_form {
3397: my ($request) = shift;
1.324 albertel 3398: my ($symb)=&get_symb($request);
1.283 albertel 3399: if (!$symb) {return '';}
3400: my $result=&checkforfile_js();
1.257 albertel 3401: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3402: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3403: $result.=$table;
1.326 albertel 3404: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3405: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.118 ng 3406: $result.=' <b>Specify a file containing the class scores for current resource'.
1.86 ng 3407: '.</b></td></tr>'."\n";
3408: $result.='<tr bgcolor=#ffffe6><td>'."\n";
3409: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3410: my $ignore=&mt('Ignore First Line');
1.86 ng 3411: $result.=<<ENDUPFORM;
1.106 albertel 3412: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3413: <input type="hidden" name="symb" value="$symb" />
3414: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3415: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3416: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3417: $upfile_select
3418: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
1.283 albertel 3419: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3420: </form>
3421: ENDUPFORM
3422: $result.='</td></tr></table>'."\n";
3423: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3424: $result.=&show_grading_menu_form($symb);
1.86 ng 3425: return $result;
3426: }
3427:
3428:
1.26 albertel 3429: sub csvuploadmap {
1.41 ng 3430: my ($request)= @_;
1.324 albertel 3431: my ($symb)=&get_symb($request);
1.41 ng 3432: if (!$symb) {return '';}
1.72 ng 3433:
1.41 ng 3434: my $datatoken;
1.257 albertel 3435: if (!$env{'form.datatoken'}) {
1.41 ng 3436: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3437: } else {
1.257 albertel 3438: $datatoken=$env{'form.datatoken'};
1.41 ng 3439: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3440: }
1.41 ng 3441: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3442: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3443: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3444: my ($i,$keyfields);
3445: if (@records) {
1.324 albertel 3446: my @fields=&csvupload_fields($symb);
1.45 ng 3447:
1.257 albertel 3448: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3449: &Apache::loncommon::csv_print_samples($request,\@records);
3450: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3451: \@fields);
3452: foreach (@fields) { $keyfields.=$_->[0].','; }
3453: chop($keyfields);
3454: } else {
3455: unshift(@fields,['none','']);
3456: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3457: \@fields);
1.311 banghart 3458: foreach my $rec (@records) {
3459: my %temp = &Apache::loncommon::record_sep($rec);
3460: if (%temp) {
3461: $keyfields=join(',',sort(keys(%temp)));
3462: last;
3463: }
3464: }
1.41 ng 3465: }
3466: }
3467: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3468: $request->print(&show_grading_menu_form($symb));
1.72 ng 3469:
1.41 ng 3470: return '';
1.27 albertel 3471: }
3472:
1.246 albertel 3473: sub csvuploadoptions {
1.41 ng 3474: my ($request)= @_;
1.324 albertel 3475: my ($symb)=&get_symb($request);
1.257 albertel 3476: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3477: my $ignore=&mt('Ignore First Line');
3478: $request->print(<<ENDPICK);
3479: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
3480: <h3><font color="#339933">Uploading Class Grade Options</font></h3>
3481: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3482: <!--
1.246 albertel 3483: <p>
3484: <label>
3485: <input type="checkbox" name="show_full_results" />
3486: Show a table of all changes
3487: </label>
3488: </p>
1.302 albertel 3489: -->
1.246 albertel 3490: <p>
3491: <label>
3492: <input type="checkbox" name="overwite_scores" checked="checked" />
3493: Overwrite any existing score
3494: </label>
3495: </p>
3496: ENDPICK
3497: my %fields=&get_fields();
3498: if (!defined($fields{'domain'})) {
1.257 albertel 3499: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3500: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3501: }
1.257 albertel 3502: foreach my $key (sort(keys(%env))) {
1.246 albertel 3503: if ($key !~ /^form\.(.*)$/) { next; }
3504: my $cleankey=$1;
3505: if ($cleankey eq 'command') { next; }
3506: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3507: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3508: }
3509: # FIXME do a check for any duplicated user ids...
3510: # FIXME do a check for any invalid user ids?...
1.290 albertel 3511: $request->print('<input type="submit" value="Assign Grades" /><br />
3512: <hr /></form>'."\n");
1.324 albertel 3513: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3514: return '';
3515: }
3516:
3517: sub get_fields {
3518: my %fields;
1.257 albertel 3519: my @keyfields = split(/\,/,$env{'form.keyfields'});
3520: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3521: if ($env{'form.upfile_associate'} eq 'reverse') {
3522: if ($env{'form.f'.$i} ne 'none') {
3523: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3524: }
3525: } else {
1.257 albertel 3526: if ($env{'form.f'.$i} ne 'none') {
3527: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3528: }
3529: }
1.27 albertel 3530: }
1.246 albertel 3531: return %fields;
3532: }
3533:
3534: sub csvuploadassign {
3535: my ($request)= @_;
1.324 albertel 3536: my ($symb)=&get_symb($request);
1.246 albertel 3537: if (!$symb) {return '';}
1.345 bowersj2 3538: my $error_msg = '';
1.246 albertel 3539: &Apache::loncommon::load_tmp_file($request);
3540: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3541: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3542: my %fields=&get_fields();
1.41 ng 3543: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3544: my $courseid=$env{'request.course.id'};
1.97 albertel 3545: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3546: my @notallowed;
1.41 ng 3547: my @skipped;
3548: my $countdone=0;
3549: foreach my $grade (@gradedata) {
3550: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3551: my $domain;
3552: if ($entries{$fields{'domain'}}) {
3553: $domain=$entries{$fields{'domain'}};
3554: } else {
1.257 albertel 3555: $domain=$env{'form.default_domain'};
1.246 albertel 3556: }
1.243 albertel 3557: $domain=~s/\s//g;
1.41 ng 3558: my $username=$entries{$fields{'username'}};
1.160 albertel 3559: $username=~s/\s//g;
1.243 albertel 3560: if (!$username) {
3561: my $id=$entries{$fields{'ID'}};
1.247 albertel 3562: $id=~s/\s//g;
1.243 albertel 3563: my %ids=&Apache::lonnet::idget($domain,$id);
3564: $username=$ids{$id};
3565: }
1.41 ng 3566: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3567: my $id=$entries{$fields{'ID'}};
3568: $id=~s/\s//g;
3569: if ($id) {
3570: push(@skipped,"$id:$domain");
3571: } else {
3572: push(@skipped,"$username:$domain");
3573: }
1.41 ng 3574: next;
3575: }
1.108 albertel 3576: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3577: if (!&canmodify($usec)) {
3578: push(@notallowed,"$username:$domain");
3579: next;
3580: }
1.244 albertel 3581: my %points;
1.41 ng 3582: my %grades;
3583: foreach my $dest (keys(%fields)) {
1.244 albertel 3584: if ($dest eq 'ID' || $dest eq 'username' ||
3585: $dest eq 'domain') { next; }
3586: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3587: if ($dest=~/stores_(.*)_points/) {
3588: my $part=$1;
3589: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3590: $symb,$domain,$username);
1.345 bowersj2 3591: if ($wgt) {
3592: $entries{$fields{$dest}}=~s/\s//g;
3593: my $pcr=$entries{$fields{$dest}} / $wgt;
3594: my $award='correct_by_override';
3595: $grades{"resource.$part.awarded"}=$pcr;
3596: $grades{"resource.$part.solved"}=$award;
3597: $points{$part}=1;
3598: } else {
3599: $error_msg = "<br />" .
3600: &mt("Some point values were assigned"
3601: ." for problems with a weight "
3602: ."of zero. These values were "
3603: ."ignored.");
3604: }
1.244 albertel 3605: } else {
3606: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3607: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3608: my $store_key=$dest;
3609: $store_key=~s/^stores/resource/;
3610: $store_key=~s/_/\./g;
3611: $grades{$store_key}=$entries{$fields{$dest}};
3612: }
1.41 ng 3613: }
1.244 albertel 3614: if (! %grades) { push(@skipped,"$username:$domain no data to store"); }
1.257 albertel 3615: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3616: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3617: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3618: $env{'request.course.id'},
3619: $domain,$username);
3620: if ($result eq 'ok') {
3621: $request->print('.');
3622: } else {
3623: $request->print("<p>
3624: <font color='red'>
3625: Failed to store student $username\@$domain.
3626: Message when trying to store was ($result)
3627: </font>
3628: </p>" );
3629: }
1.41 ng 3630: $request->rflush();
3631: $countdone++;
3632: }
3633: $request->print("<br />Stored $countdone students\n");
3634: if (@skipped) {
1.325 www 3635: $request->print('<p><font size="+1"><b>Skipped Students</b></font></p>');
1.106 albertel 3636: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3637: }
3638: if (@notallowed) {
3639: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
3640: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3641: }
1.106 albertel 3642: $request->print("<br />\n");
1.324 albertel 3643: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 3644: return $error_msg;
1.26 albertel 3645: }
1.44 ng 3646: #------------- end of section for handling csv file upload ---------
3647: #
3648: #-------------------------------------------------------------------
3649: #
1.122 ng 3650: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3651: #
3652: #--- Select a page/sequence and a student to grade
1.68 ng 3653: sub pickStudentPage {
3654: my ($request) = shift;
3655:
3656: $request->print(<<LISTJAVASCRIPT);
3657: <script type="text/javascript" language="javascript">
3658:
3659: function checkPickOne(formname) {
1.76 ng 3660: if (radioSelection(formname.student) == null) {
1.68 ng 3661: alert("Please select the student you wish to grade.");
3662: return;
3663: }
1.125 ng 3664: ptr = pullDownSelection(formname.selectpage);
3665: formname.page.value = formname["page"+ptr].value;
3666: formname.title.value = formname["title"+ptr].value;
1.68 ng 3667: formname.submit();
3668: }
3669:
3670: </script>
3671: LISTJAVASCRIPT
1.118 ng 3672: &commonJSfunctions($request);
1.324 albertel 3673: my ($symb) = &get_symb($request);
1.257 albertel 3674: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3675: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3676: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3677:
3678: my $result='<h3><font color="#339933"> '.
3679: 'Manual Grading by Page or Sequence</font></h3>';
3680:
1.80 ng 3681: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3682: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3683: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3684: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3685: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3686: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3687: my $ctr=0;
1.68 ng 3688: foreach (@$titles) {
3689: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3690: $result.='<option value="'.$ctr.'" '.
1.71 ng 3691: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3692: '>'.$showtitle.'</option>'."\n";
1.70 ng 3693: $ctr++;
1.68 ng 3694: }
1.326 albertel 3695: $result.= '</select>'."<br />\n";
1.70 ng 3696: $ctr=0;
3697: foreach (@$titles) {
3698: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3699: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3700: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3701: $ctr++;
3702: }
1.72 ng 3703: $result.='<input type="hidden" name="page" />'."\n".
3704: '<input type="hidden" name="title" />'."\n";
1.68 ng 3705:
1.288 albertel 3706: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3707: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3708:
1.71 ng 3709: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3710: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3711: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3712: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3713:
1.68 ng 3714: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3715: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3716: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.80 ng 3717: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 3718: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3719:
1.80 ng 3720: $result.=' <input type="button" '.
1.126 ng 3721: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3722:
1.68 ng 3723: $request->print($result);
3724:
1.326 albertel 3725: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br />'.
1.68 ng 3726: '<table border="0"><tr><td bgcolor="#777777">'.
3727: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3728: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3729: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3730: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3731: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3732:
1.76 ng 3733: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3734: my $ptr = 1;
1.294 albertel 3735: foreach my $student (sort
3736: {
3737: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3738: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3739: }
3740: return $a cmp $b;
3741: } (keys(%$fullname))) {
1.68 ng 3742: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3743: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3744: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3745: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3746: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3747: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3748: $ptr++;
3749: }
1.126 ng 3750: $studentTable.='</td><td> </td><td> ' if ($ptr%2 == 0);
1.68 ng 3751: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.126 ng 3752: $studentTable.='<input type="button" '.
3753: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3754:
1.324 albertel 3755: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 3756: $request->print($studentTable);
3757:
3758: return '';
3759: }
3760:
3761: sub getSymbMap {
1.74 albertel 3762: my ($request) = @_;
1.132 bowersj2 3763: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3764:
3765: my %symbx = ();
3766: my @titles = ();
1.117 bowersj2 3767: my $minder = 0;
3768:
3769: # Gather every sequence that has problems.
1.240 albertel 3770: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3771: 1,0,1);
1.117 bowersj2 3772: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3773: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.117 bowersj2 3774: my $title = $minder.'.'.$sequence->compTitle();
3775: push @titles, $title; # minder in case two titles are identical
3776: $symbx{$title} = $sequence->symb();
3777: $minder++;
1.241 albertel 3778: }
1.68 ng 3779: }
3780: return \@titles,\%symbx;
3781: }
3782:
1.72 ng 3783: #
3784: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3785: sub displayPage {
3786: my ($request) = shift;
3787:
1.324 albertel 3788: my ($symb) = &get_symb($request);
1.257 albertel 3789: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3790: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3791: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3792: my $pageTitle = $env{'form.page'};
1.103 albertel 3793: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3794: my ($uname,$udom) = split(/:/,$env{'form.student'});
3795: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3796:
3797: #need to make sure we have the correct data for later EXT calls,
3798: #thus invalidate the cache
3799: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3800: $env{'course.'.$env{'request.course.id'}.'.num'},
3801: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3802: &Apache::lonnet::clear_EXT_cache_status();
3803:
1.103 albertel 3804: if (!&canview($usec)) {
1.257 albertel 3805: $request->print('<font color="red">Unable to view requested student.('.$env{'form.student'}.')</font>');
1.324 albertel 3806: $request->print(&show_grading_menu_form($symb));
1.103 albertel 3807: return;
3808: }
1.257 albertel 3809: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3810: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3811: '</h3>'."\n";
1.71 ng 3812: &sub_page_js($request);
3813: $request->print($result);
3814:
1.132 bowersj2 3815: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3816: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3817: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3818: if (!$map) {
3819: $request->print('<font color="red">Unable to view requested sequence. ('.$resUrl.')</font>');
1.324 albertel 3820: $request->print(&show_grading_menu_form($symb));
1.288 albertel 3821: return;
3822: }
1.68 ng 3823: my $iterator = $navmap->getIterator($map->map_start(),
3824: $map->map_finish());
3825:
1.71 ng 3826: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3827: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3828: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3829: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3830: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3831: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.72 ng 3832: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3833: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3834: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3835:
3836: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
3837: '/check.gif" height="16" border="0" />';
3838:
1.118 ng 3839: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
3840: ' symbol.'."\n".
1.71 ng 3841: '<table border="0"><tr><td bgcolor="#777777">'.
3842: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 3843: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 3844: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 3845:
1.329 albertel 3846: &Apache::lonxml::clear_problem_counter();
1.196 albertel 3847: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 3848: $iterator->next(); # skip the first BEGIN_MAP
3849: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3850: while ($depth > 0) {
1.68 ng 3851: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3852: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 3853:
1.235 albertel 3854: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3855: my $parts = $curRes->parts();
1.68 ng 3856: my $title = $curRes->compTitle();
1.71 ng 3857: my $symbx = $curRes->symb();
1.196 albertel 3858: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 3859: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 3860: $studentTable.='<td valign="top">';
1.257 albertel 3861: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 3862: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
3863: undef,'both');
1.71 ng 3864: } else {
1.257 albertel 3865: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'});
1.80 ng 3866: $companswer =~ s|<form(.*?)>||g;
3867: $companswer =~ s|</form>||g;
1.71 ng 3868: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 3869: # $companswer =~ s/$1/ /ms;
1.326 albertel 3870: # $request->print('match='.$1."<br />\n");
1.71 ng 3871: # }
1.116 ng 3872: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.326 albertel 3873: $studentTable.=' <b>'.$title.'</b> <br /> <b>Correct answer:</b><br />'.$companswer;
1.71 ng 3874: }
3875:
1.257 albertel 3876: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 3877:
1.257 albertel 3878: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 3879: if ($record{'version'} eq '') {
3880: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
3881: } else {
1.116 ng 3882: my %responseType = ();
3883: foreach my $partid (@{$parts}) {
1.147 albertel 3884: my @responseIds =$curRes->responseIds($partid);
3885: my @responseType =$curRes->responseType($partid);
3886: my %responseIds;
3887: for (my $i=0;$i<=$#responseIds;$i++) {
3888: $responseIds{$responseIds[$i]}=$responseType[$i];
3889: }
3890: $responseType{$partid} = \%responseIds;
1.116 ng 3891: }
1.148 albertel 3892: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 3893:
1.71 ng 3894: }
1.257 albertel 3895: } elsif ($env{'form.lastSub'} eq 'all') {
3896: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 3897: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 3898: $env{'request.course.id'},
1.71 ng 3899: '','.submission');
3900:
3901: }
1.103 albertel 3902: if (&canmodify($usec)) {
3903: foreach my $partid (@{$parts}) {
3904: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
3905: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
3906: $question++;
3907: }
1.196 albertel 3908: $prob++;
1.71 ng 3909: }
3910: $studentTable.='</td></tr>';
1.68 ng 3911:
1.103 albertel 3912: }
1.68 ng 3913: $curRes = $iterator->next();
3914: }
3915:
1.71 ng 3916: $studentTable.='</td></tr></table></td></tr></table>'."\n".
1.125 ng 3917: '<input type="button" value="Save" '.
1.71 ng 3918: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
3919: '</form>'."\n";
1.324 albertel 3920: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 3921: $request->print($studentTable);
3922:
3923: return '';
1.119 ng 3924: }
3925:
3926: sub displaySubByDates {
1.148 albertel 3927: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 3928: my $isCODE=0;
1.335 albertel 3929: my $isTask = ($symb =~/\.task$/);
1.224 albertel 3930: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 3931: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
3932: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
3933: '<td><b>Date/Time</b></td>'.
1.224 albertel 3934: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 3935: '<td><b>Submission</b></td>'.
3936: '<td><b>Status </b></td></tr>';
3937: my ($version);
3938: my %mark;
1.148 albertel 3939: my %orders;
1.119 ng 3940: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 3941: if (!exists($$record{'1:timestamp'})) {
3942: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
3943: }
1.335 albertel 3944:
3945: my $interaction;
1.119 ng 3946: for ($version=1;$version<=$$record{'version'};$version++) {
3947: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
1.335 albertel 3948: if (exists($$record{$version.':resource.0.version'})) {
3949: $interaction = $$record{$version.':resource.0.version'};
3950: }
3951:
3952: my $where = ($isTask ? "$version:resource.$interaction"
3953: : "$version:resource");
3954: #&Apache::lonnet::logthis(" got $where");
1.119 ng 3955: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 3956: if ($isCODE) {
3957: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
3958: }
1.119 ng 3959: my @versionKeys = split(/\:/,$$record{$version.':keys'});
3960: my @displaySub = ();
3961: foreach my $partid (@{$parts}) {
1.335 albertel 3962: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
3963: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
3964:
3965:
1.122 ng 3966: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 3967: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 3968: foreach my $matchKey (@matchKey) {
1.198 albertel 3969: if (exists($$record{$version.':'.$matchKey}) &&
3970: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 3971:
3972: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
3973: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
3974: #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey});
1.207 albertel 3975: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.147 albertel 3976: $displaySub[0].='<font color="#999999">(ID '.
1.207 albertel 3977: $responseId.')</font> <b>';
1.335 albertel 3978: if ($$record{"$where.$partid.tries"} eq '') {
1.147 albertel 3979: $displaySub[0].='Trial not counted';
3980: } else {
3981: $displaySub[0].='Trial '.
1.335 albertel 3982: $$record{"$where.$partid.tries"};
1.147 albertel 3983: }
1.335 albertel 3984: my $responseType=($isTask ? 'Task'
3985: : $responseType->{$partid}->{$responseId});
1.148 albertel 3986: if (!exists($orders{$partid})) { $orders{$partid}={}; }
3987: if (!exists($orders{$partid}->{$responseId})) {
3988: $orders{$partid}->{$responseId}=
3989: &get_order($partid,$responseId,$symb,$uname,$udom);
3990: }
1.147 albertel 3991: $displaySub[0].='</b> '.
1.336 albertel 3992: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 3993: }
3994: }
1.335 albertel 3995: if (exists($$record{"$where.$partid.checkedin"})) {
3996: $displaySub[1].='Checked in by '.
3997: $$record{"$where.$partid.checkedin"}.' into slot '.
3998: $$record{"$where.$partid.checkedin.slot"}.
3999: '<br />';
4000: }
4001: if (exists $$record{"$where.$partid.award"}) {
1.207 albertel 4002: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.335 albertel 4003: lc($$record{"$where.$partid.award"}).' '.
4004: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4005: '<br />';
4006: }
1.335 albertel 4007: if (exists $$record{"$where.$partid.regrader"}) {
4008: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4009: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4010: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4011: $displaySub[2].=
4012: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4013: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4014: }
4015: }
4016: # needed because old essay regrader has not parts info
4017: if (exists $$record{"$version:resource.regrader"}) {
4018: $displaySub[2].=$$record{"$version:resource.regrader"};
4019: }
4020: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4021: if ($displaySub[2]) {
4022: $studentTable.='Manually graded by '.$displaySub[2];
4023: }
4024: $studentTable.=' </td></tr>';
4025:
1.119 ng 4026: }
4027: $studentTable.='</table></td></tr></table>';
4028: return $studentTable;
1.71 ng 4029: }
4030:
4031: sub updateGradeByPage {
4032: my ($request) = shift;
4033:
1.257 albertel 4034: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4035: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4036: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4037: my $pageTitle = $env{'form.page'};
1.103 albertel 4038: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4039: my ($uname,$udom) = split(/:/,$env{'form.student'});
4040: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4041: if (!&canmodify($usec)) {
1.257 albertel 4042: $request->print('<font color="red">Unable to modify requested student.('.$env{'form.student'}.'</font>');
1.324 albertel 4043: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4044: return;
4045: }
1.257 albertel 4046: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
4047: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4048: '</h3>'."\n";
1.70 ng 4049:
1.68 ng 4050: $request->print($result);
4051:
1.132 bowersj2 4052: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4053: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4054: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4055: if (!$map) {
4056: $request->print('<font color="red">Unable to grade requested sequence. ('.$resUrl.')</font>');
1.324 albertel 4057: my ($symb)=&get_symb($request);
4058: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4059: return;
4060: }
1.71 ng 4061: my $iterator = $navmap->getIterator($map->map_start(),
4062: $map->map_finish());
1.70 ng 4063:
1.71 ng 4064: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 4065: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 4066: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 4067: '<td><b> Title </b></td>'.
4068: '<td><b> Previous Score </b></td>'.
4069: '<td><b> New Score </b></td></tr>';
4070:
4071: $iterator->next(); # skip the first BEGIN_MAP
4072: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4073: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4074: while ($depth > 0) {
1.71 ng 4075: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4076: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4077:
4078: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 4079: my $parts = $curRes->parts();
1.71 ng 4080: my $title = $curRes->compTitle();
4081: my $symbx = $curRes->symb();
1.196 albertel 4082: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4083: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4084: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4085:
4086: my %newrecord=();
4087: my @displayPts=();
1.269 raeburn 4088: my %aggregate = ();
4089: my $aggregateflag = 0;
1.71 ng 4090: foreach my $partid (@{$parts}) {
1.257 albertel 4091: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4092: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4093:
1.257 albertel 4094: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4095: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4096: my $partial = $newpts/$wgt;
4097: my $score;
4098: if ($partial > 0) {
4099: $score = 'correct_by_override';
1.125 ng 4100: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4101: $score = 'incorrect_by_override';
4102: }
1.257 albertel 4103: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4104: if ($dropMenu eq 'excused') {
1.71 ng 4105: $partial = '';
4106: $score = 'excused';
1.125 ng 4107: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4108: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4109: $newrecord{'resource.'.$partid.'.tries'} = 0;
4110: $newrecord{'resource.'.$partid.'.solved'} = '';
4111: $newrecord{'resource.'.$partid.'.award'} = '';
4112: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4113: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4114: $changeflag++;
4115: $newpts = '';
1.269 raeburn 4116:
4117: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4118: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4119: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4120: if ($aggtries > 0) {
4121: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4122: $aggregateflag = 1;
4123: }
1.71 ng 4124: }
1.324 albertel 4125: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4126: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4127: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4128: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4129: ' <br />';
1.207 albertel 4130: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4131: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4132: ' <br />';
1.71 ng 4133:
4134: $question++;
1.125 ng 4135: next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
4136:
1.71 ng 4137: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4138: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4139: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4140: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4141:
4142: $changeflag++;
4143: }
4144: if (scalar(keys(%newrecord)) > 0) {
1.257 albertel 4145: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4146: $udom,$uname);
4147: }
1.269 raeburn 4148: if ($aggregateflag) {
4149: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4150: $env{'course.'.$env{'request.course.id'}.'.domain'},
4151: $env{'course.'.$env{'request.course.id'}.'.num'});
4152: }
1.125 ng 4153:
1.71 ng 4154: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4155: '<td valign="top">'.$displayPts[1].'</td>'.
4156: '</tr>';
1.68 ng 4157:
1.196 albertel 4158: $prob++;
1.68 ng 4159: }
1.71 ng 4160: $curRes = $iterator->next();
1.68 ng 4161: }
1.98 albertel 4162:
1.71 ng 4163: $studentTable.='</td></tr></table></td></tr></table>';
1.324 albertel 4164: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.76 ng 4165: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4166: 'The scores were changed for '.
4167: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4168: $request->print($grademsg.$studentTable);
1.68 ng 4169:
1.70 ng 4170: return '';
4171: }
4172:
1.72 ng 4173: #-------- end of section for handling grading by page/sequence ---------
4174: #
4175: #-------------------------------------------------------------------
4176:
1.75 albertel 4177: #--------------------Scantron Grading-----------------------------------
4178: #
4179: #------ start of section for handling grading by page/sequence ---------
4180:
1.81 albertel 4181: sub defaultFormData {
1.324 albertel 4182: my ($symb)=@_;
1.81 albertel 4183: return '
4184: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 4185: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4186: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4187: }
4188:
1.75 albertel 4189: sub getSequenceDropDown {
4190: my ($request,$symb)=@_;
4191: my $result='<select name="selectpage">'."\n";
4192: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4193: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4194: my $ctr=0;
4195: foreach (@$titles) {
4196: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4197: $result.='<option value="'.$$symbx{$_}.'" '.
4198: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4199: '>'.$showtitle.'</option>'."\n";
4200: $ctr++;
4201: }
4202: $result.= '</select>';
4203: return $result;
4204: }
4205:
1.202 albertel 4206: sub scantron_filenames {
1.257 albertel 4207: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4208: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4209: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.162 albertel 4210: &Apache::loncommon::propath($cdom,$cname));
1.202 albertel 4211: my @possiblenames;
1.201 albertel 4212: foreach my $filename (sort(@files)) {
1.157 albertel 4213: ($filename)=split(/&/,$filename);
4214: if ($filename!~/^scantron_orig_/) { next ; }
4215: $filename=~s/^scantron_orig_//;
1.202 albertel 4216: push(@possiblenames,$filename);
4217: }
4218: return @possiblenames;
4219: }
4220:
4221: sub scantron_uploads {
1.209 ng 4222: my ($file2grade) = @_;
1.202 albertel 4223: my $result= '<select name="scantron_selectfile">';
4224: $result.="<option></option>";
4225: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4226: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4227: }
4228: $result.="</select>";
4229: return $result;
4230: }
4231:
1.82 albertel 4232: sub scantron_scantab {
4233: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4234: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4235: $result.='<option></option>'."\n";
1.82 albertel 4236: foreach my $line (<$fh>) {
4237: my ($name,$descrip)=split(/:/,$line);
4238: if ($name =~ /^\#/) { next; }
4239: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4240: }
4241: $result.='</select>'."\n";
4242:
4243: return $result;
4244: }
4245:
1.186 albertel 4246: sub scantron_CODElist {
1.257 albertel 4247: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4248: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4249: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4250: my $namechoice='<option></option>';
1.225 albertel 4251: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4252: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4253: if ($name =~ /^type\0/) { next; }
1.186 albertel 4254: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4255: }
4256: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4257: return $namechoice;
4258: }
4259:
4260: sub scantron_CODEunique {
4261: my $result='<nobr>
1.272 albertel 4262: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4263: value="yes" checked="checked" /> Yes </label>
1.186 albertel 4264: </nobr>
4265: <nobr>
1.272 albertel 4266: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4267: value="no" /> No </label>
1.186 albertel 4268: </nobr>';
4269: return $result;
4270: }
4271:
1.75 albertel 4272: sub scantron_selectphase {
1.209 ng 4273: my ($r,$file2grade) = @_;
1.324 albertel 4274: my ($symb)=&get_symb($r);
1.75 albertel 4275: if (!$symb) {return '';}
4276: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.324 albertel 4277: my $default_form_data=&defaultFormData($symb);
4278: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4279: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4280: my $format_selector=&scantron_scantab();
1.186 albertel 4281: my $CODE_selector=&scantron_CODElist();
4282: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4283: my $result;
1.157 albertel 4284: #FIXME allow instructor to be able to download the scantron file
4285: # and to upload it,
1.75 albertel 4286: $result.= <<SCANTRONFORM;
1.162 albertel 4287: <table width="100%" border="0">
1.75 albertel 4288: <tr>
1.226 albertel 4289: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4290: <td bgcolor="#777777">
1.203 albertel 4291: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4292: $default_form_data
1.75 albertel 4293: <table width="100%" border="0">
4294: <tr bgcolor="#e6ffff">
1.174 albertel 4295: <td colspan="2">
4296: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4297: </td>
4298: </tr>
4299: <tr bgcolor="#ffffe6">
1.174 albertel 4300: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4301: </tr>
4302: <tr bgcolor="#ffffe6">
1.174 albertel 4303: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4304: </tr>
1.82 albertel 4305: <tr bgcolor="#ffffe6">
1.174 albertel 4306: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4307: </tr>
1.157 albertel 4308: <tr bgcolor="#ffffe6">
1.186 albertel 4309: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4310: </tr>
4311: <tr bgcolor="#ffffe6">
4312: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4313: </tr>
4314: <tr bgcolor="#ffffe6">
1.187 albertel 4315: <td> Options: </td>
4316: <td>
1.272 albertel 4317: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
1.331 albertel 4318: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label> <br />
4319: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
1.187 albertel 4320: </td>
4321: </tr>
4322: <tr bgcolor="#ffffe6">
1.174 albertel 4323: <td colspan="2">
1.265 www 4324: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4325: </td>
4326: </tr>
4327: </table>
1.226 albertel 4328: </td>
4329: </form>
1.162 albertel 4330: </tr>
4331: SCANTRONFORM
4332:
4333: $r->print($result);
4334:
1.257 albertel 4335: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4336: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4337:
4338: $r->print(<<SCANTRONFORM);
4339: <tr>
4340: <td bgcolor="#777777">
4341: <table width="100%" border="0">
4342: <tr bgcolor="#e6ffff">
4343: <td>
1.174 albertel 4344: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4345: </td>
4346: </tr>
4347: <tr bgcolor="#ffffe6">
4348: <td>
4349: SCANTRONFORM
1.324 albertel 4350: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 4351: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4352: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4353: $r->print(<<UPLOAD);
4354: <script type="text/javascript" language="javascript">
4355: function checkUpload(formname) {
4356: if (formname.upfile.value == "") {
4357: alert("Please use the browse button to select a file from your local directory.");
4358: return false;
4359: }
4360: formname.submit();
4361: }
4362: </script>
4363:
4364: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4365: $default_form_data
4366: <input name='courseid' type='hidden' value='$cnum' />
4367: <input name='domainid' type='hidden' value='$cdom' />
4368: <input name='command' value='scantronupload_save' type='hidden' />
4369: File to upload:<input type="file" name="upfile" size="50" />
4370: <br />
4371: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4372: </form>
4373: UPLOAD
1.162 albertel 4374:
4375: $r->print(<<SCANTRONFORM);
4376: </td>
4377: </tr>
1.75 albertel 4378: </table>
4379: </td>
4380: </tr>
1.162 albertel 4381: SCANTRONFORM
4382: }
1.187 albertel 4383: $r->print(<<SCANTRONFORM);
4384: <tr>
1.226 albertel 4385: <form action='/adm/grades' name='scantron_download'>
4386: <td bgcolor="#777777">
1.187 albertel 4387: <input type="hidden" name="command" value="scantron_download" />
4388: <table width="100%" border="0">
4389: <tr bgcolor="#e6ffff">
4390: <td colspan="2">
4391: <b>Download a scoring office file</b>
4392: </td>
4393: </tr>
4394: <tr bgcolor="#ffffe6">
4395: <td> Filename of scoring office file: </td><td> $file_selector </td>
4396: </tr>
4397: <tr bgcolor="#ffffe6">
4398: <td colspan="2">
1.293 www 4399: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4400: </td>
4401: </tr>
4402: </table>
1.226 albertel 4403: </td>
4404: </form>
1.187 albertel 4405: </tr>
4406: SCANTRONFORM
1.162 albertel 4407:
4408: $r->print(<<SCANTRONFORM);
1.75 albertel 4409: </table>
1.81 albertel 4410: $grading_menu_button
1.75 albertel 4411: SCANTRONFORM
4412:
1.162 albertel 4413: return
1.75 albertel 4414: }
4415:
1.82 albertel 4416: sub get_scantron_config {
4417: my ($which) = @_;
4418: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4419: my %config;
1.157 albertel 4420: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4421: foreach my $line (<$fh>) {
4422: my ($name,$descrip)=split(/:/,$line);
4423: if ($name ne $which ) { next; }
4424: chomp($line);
4425: my @config=split(/:/,$line);
4426: $config{'name'}=$config[0];
4427: $config{'description'}=$config[1];
4428: $config{'CODElocation'}=$config[2];
4429: $config{'CODEstart'}=$config[3];
4430: $config{'CODElength'}=$config[4];
4431: $config{'IDstart'}=$config[5];
4432: $config{'IDlength'}=$config[6];
4433: $config{'Qstart'}=$config[7];
4434: $config{'Qlength'}=$config[8];
4435: $config{'Qoff'}=$config[9];
4436: $config{'Qon'}=$config[10];
1.157 albertel 4437: $config{'PaperID'}=$config[11];
4438: $config{'PaperIDlength'}=$config[12];
4439: $config{'FirstName'}=$config[13];
4440: $config{'FirstNamelength'}=$config[14];
4441: $config{'LastName'}=$config[15];
4442: $config{'LastNamelength'}=$config[16];
1.82 albertel 4443: last;
4444: }
4445: return %config;
4446: }
4447:
4448: sub username_to_idmap {
4449: my ($classlist)= @_;
4450: my %idmap;
4451: foreach my $student (keys(%$classlist)) {
4452: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4453: $student;
4454: }
4455: return %idmap;
4456: }
4457:
1.157 albertel 4458: sub scantron_fixup_scanline {
4459: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4460: if ($field eq 'ID') {
4461: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4462: return ($line,1,'New value too large');
1.157 albertel 4463: }
4464: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4465: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4466: $args->{'newid'});
4467: }
4468: substr($line,$$scantron_config{'IDstart'}-1,
4469: $$scantron_config{'IDlength'})=$args->{'newid'};
4470: if ($args->{'newid'}=~/^\s*$/) {
4471: &scan_data($scan_data,"$whichline.user",
4472: $args->{'username'}.':'.$args->{'domain'});
4473: }
1.186 albertel 4474: } elsif ($field eq 'CODE') {
1.192 albertel 4475: if ($args->{'CODE_ignore_dup'}) {
4476: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4477: }
4478: &scan_data($scan_data,"$whichline.useCODE",'1');
4479: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4480: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4481: return ($line,1,'New CODE value too large');
4482: }
4483: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4484: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4485: }
4486: substr($line,$$scantron_config{'CODEstart'}-1,
4487: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4488: }
1.157 albertel 4489: } elsif ($field eq 'answer') {
4490: my $length=$scantron_config->{'Qlength'};
4491: my $off=$scantron_config->{'Qoff'};
4492: my $on=$scantron_config->{'Qon'};
4493: my $answer=${off}x$length;
4494: if ($args->{'response'} eq 'none') {
4495: &scan_data($scan_data,
4496: "$whichline.no_bubble.".$args->{'question'},'1');
4497: } else {
1.274 albertel 4498: if ($on eq 'letter') {
4499: my @alphabet=('A'..'Z');
4500: $answer=$alphabet[$args->{'response'}];
4501: } elsif ($on eq 'number') {
4502: $answer=$args->{'response'}+1;
4503: } else {
4504: substr($answer,$args->{'response'},1)=$on;
4505: }
1.157 albertel 4506: &scan_data($scan_data,
4507: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4508: }
4509: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4510: substr($line,$where-1,$length)=$answer;
4511: }
4512: return $line;
4513: }
4514:
4515: sub scan_data {
4516: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4517: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4518: if (defined($value)) {
4519: $scan_data->{$filename.'_'.$key} = $value;
4520: }
4521: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4522: return $scan_data->{$filename.'_'.$key};
4523: }
4524:
1.82 albertel 4525: sub scantron_parse_scanline {
1.194 albertel 4526: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4527: my %record;
4528: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4529: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4530: if (!($$scantron_config{'CODElocation'} eq 0 ||
4531: $$scantron_config{'CODElocation'} eq 'none')) {
4532: if ($$scantron_config{'CODElocation'} < 0 ||
4533: $$scantron_config{'CODElocation'} eq 'letter' ||
4534: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4535: $record{'scantron.CODE'}=substr($data,
4536: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4537: $$scantron_config{'CODElength'});
1.191 albertel 4538: if (&scan_data($scan_data,"$whichline.useCODE")) {
4539: $record{'scantron.useCODE'}=1;
4540: }
1.192 albertel 4541: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4542: $record{'scantron.CODE_ignore_dup'}=1;
4543: }
1.82 albertel 4544: } else {
4545: #FIXME interpret first N questions
4546: }
4547: }
1.83 albertel 4548: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4549: $$scantron_config{'IDlength'});
1.157 albertel 4550: $record{'scantron.PaperID'}=
4551: substr($data,$$scantron_config{'PaperID'}-1,
4552: $$scantron_config{'PaperIDlength'});
4553: $record{'scantron.FirstName'}=
4554: substr($data,$$scantron_config{'FirstName'}-1,
4555: $$scantron_config{'FirstNamelength'});
4556: $record{'scantron.LastName'}=
4557: substr($data,$$scantron_config{'LastName'}-1,
4558: $$scantron_config{'LastNamelength'});
1.194 albertel 4559: if ($justHeader) { return \%record; }
4560:
1.82 albertel 4561: my @alphabet=('A'..'Z');
4562: my $questnum=0;
4563: while ($questions) {
4564: $questnum++;
4565: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4566: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4567: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4568: if ($$scantron_config{'Qon'} eq 'letter') {
1.274 albertel 4569: if ($currentquest eq '?') {
4570: push(@{$record{'scantron.doubleerror'}},$questnum);
4571: $record{"scantron.$questnum.answer"}='';
4572: } elsif (!$currentquest
4573: || $currentquest eq $$scantron_config{'Qoff'}
4574: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4575: $record{"scantron.$questnum.answer"}='';
4576: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4577: push(@{$record{"scantron.missingerror"}},$questnum);
4578: }
4579: } else {
4580: $record{"scantron.$questnum.answer"}=$currentquest;
4581: }
4582: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.274 albertel 4583: if ($currentquest eq '?') {
4584: push(@{$record{'scantron.doubleerror'}},$questnum);
4585: $record{"scantron.$questnum.answer"}='';
4586: } elsif (!$currentquest
4587: || $currentquest eq $$scantron_config{'Qoff'}
4588: || $currentquest !~ /^\d$/) {
1.239 albertel 4589: $record{"scantron.$questnum.answer"}='';
4590: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4591: push(@{$record{"scantron.missingerror"}},$questnum);
4592: }
4593: } else {
4594: $record{"scantron.$questnum.answer"}=
4595: $alphabet[$currentquest-1];
4596: }
1.82 albertel 4597: } else {
1.239 albertel 4598: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4599: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4600: $record{"scantron.$questnum.answer"}='';
4601: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4602: push(@{$record{"scantron.missingerror"}},$questnum);
4603: }
4604: } else {
4605: $record{"scantron.$questnum.answer"}=
4606: $alphabet[length($array[0])];
4607: }
4608: if (scalar(@array) gt 2) {
4609: push(@{$record{'scantron.doubleerror'}},$questnum);
4610: my @ans=@array;
4611: my $i=length($ans[0]);shift(@ans);
4612: while ($#ans) {
4613: $i+=length($ans[0])+1;
4614: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4615: shift(@ans);
4616: }
4617: }
1.82 albertel 4618: }
4619: }
1.83 albertel 4620: $record{'scantron.maxquest'}=$questnum;
4621: return \%record;
1.82 albertel 4622: }
4623:
4624: sub scantron_add_delay {
1.140 albertel 4625: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4626: push(@$delayqueue,
4627: {'line' => $scanline, 'emsg' => $errormessage,
4628: 'ecode' => $errorcode }
4629: );
1.82 albertel 4630: }
4631:
4632: sub scantron_find_student {
1.157 albertel 4633: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4634: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4635: if ($scanID =~ /^\s*$/) {
4636: return &scan_data($scan_data,"$line.user");
4637: }
1.83 albertel 4638: foreach my $id (keys(%$idmap)) {
1.157 albertel 4639: if (lc($id) eq lc($scanID)) {
4640: return $$idmap{$id};
4641: }
1.83 albertel 4642: }
4643: return undef;
4644: }
4645:
4646: sub scantron_filter {
4647: my ($curres)=@_;
1.331 albertel 4648:
4649: if (ref($curres) && $curres->is_problem()) {
4650: # if the user has asked to not have either hidden
4651: # or 'randomout' controlled resources to be graded
4652: # don't include them
4653: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
4654: && $curres->randomout) {
4655: return 0;
4656: }
1.83 albertel 4657: return 1;
4658: }
4659: return 0;
1.82 albertel 4660: }
4661:
1.157 albertel 4662: sub scantron_process_corrections {
4663: my ($r) = @_;
1.257 albertel 4664: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4665: my ($scanlines,$scan_data)=&scantron_getfile();
4666: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4667: my $which=$env{'form.scantron_line'};
1.200 albertel 4668: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4669: my ($skip,$err,$errmsg);
1.257 albertel 4670: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4671: $skip=1;
1.257 albertel 4672: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4673: my $newstudent=$env{'form.scantron_username'}.':'.
4674: $env{'form.scantron_domain'};
1.157 albertel 4675: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4676: ($line,$err,$errmsg)=
4677: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4678: 'ID',{'newid'=>$newid,
1.257 albertel 4679: 'username'=>$env{'form.scantron_username'},
4680: 'domain'=>$env{'form.scantron_domain'}});
4681: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4682: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4683: my $newCODE;
1.192 albertel 4684: my %args;
1.190 albertel 4685: if ($resolution eq 'use_unfound') {
1.191 albertel 4686: $newCODE='use_unfound';
1.190 albertel 4687: } elsif ($resolution eq 'use_found') {
1.257 albertel 4688: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4689: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4690: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4691: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4692: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4693: }
1.257 albertel 4694: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4695: $args{'CODE_ignore_dup'}=1;
4696: }
4697: $args{'CODE'}=$newCODE;
1.186 albertel 4698: ($line,$err,$errmsg)=
4699: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4700: 'CODE',\%args);
1.257 albertel 4701: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4702: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4703: ($line,$err,$errmsg)=
4704: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4705: $which,'answer',
4706: { 'question'=>$question,
1.257 albertel 4707: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4708: if ($err) { last; }
4709: }
4710: }
4711: if ($err) {
1.287 albertel 4712: $r->print("<font color='red'>Unable to accept last correction, an error occurred :$errmsg:</font>");
1.157 albertel 4713: } else {
1.200 albertel 4714: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4715: &scantron_putfile($scanlines,$scan_data);
4716: }
4717: }
4718:
1.200 albertel 4719: sub reset_skipping_status {
4720: my ($scanlines,$scan_data)=&scantron_getfile();
4721: &scan_data($scan_data,'remember_skipping',undef,1);
4722: &scantron_putfile(undef,$scan_data);
4723: }
4724:
4725: sub allow_skipping {
4726: my ($scan_data,$i)=@_;
4727: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4728: delete($remembered{$i});
4729: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4730: }
4731:
4732: sub should_be_skipped {
4733: my ($scan_data,$i)=@_;
1.257 albertel 4734: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4735: # not redoing old skips
4736: return 0;
4737: }
4738: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4739: if (exists($remembered{$i})) { return 0; }
4740: return 1;
4741: }
4742:
4743: sub remember_current_skipped {
4744: my ($scanlines,$scan_data)=&scantron_getfile();
4745: my %to_remember;
4746: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4747: if ($scanlines->{'skipped'}[$i]) {
4748: $to_remember{$i}=1;
4749: }
4750: }
4751: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4752: &scantron_putfile(undef,$scan_data);
4753: }
4754:
4755: sub check_for_error {
4756: my ($r,$result)=@_;
4757: if ($result ne 'ok' && $result ne 'not_found' ) {
4758: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4759: }
4760: }
1.157 albertel 4761:
1.203 albertel 4762: sub scantron_warning_screen {
4763: my ($button_text)=@_;
1.257 albertel 4764: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4765: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
4766: my $CODElist="a";
4767: if ($scantron_config{'CODElocation'} &&
4768: $scantron_config{'CODEstart'} &&
4769: $scantron_config{'CODElength'}) {
4770: $CODElist=$env{'form.scantron_CODElist'};
4771: if ($CODElist eq '') { $CODElist='<font color="red">None</font>'; }
4772: $CODElist=
4773: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
4774: $CODElist.'</tt></td></tr>';
4775: }
1.203 albertel 4776: return (<<STUFF);
4777: <p>
4778: <font color="red">Please double check the information
4779: below before clicking on '$button_text'</font>
4780: </p>
4781: <table>
1.284 albertel 4782: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4783: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4784: $CODElist
1.203 albertel 4785: </table>
4786: </font>
4787: <br />
4788: <p> If this information is correct, please click on '$button_text'.</p>
4789: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4790:
4791: <br />
4792: STUFF
4793: }
4794:
4795: sub scantron_do_warning {
4796: my ($r)=@_;
1.324 albertel 4797: my ($symb)=&get_symb($r);
1.203 albertel 4798: if (!$symb) {return '';}
1.324 albertel 4799: my $default_form_data=&defaultFormData($symb);
1.203 albertel 4800: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 4801: if ( $env{'form.selectpage'} eq '' ||
4802: $env{'form.scantron_selectfile'} eq '' ||
4803: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 4804: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 4805: if ( $env{'form.selectpage'} eq '') {
1.237 albertel 4806: $r->print('<p><font color="red">You have not selected a Sequence to grade</font></p>');
4807: }
1.257 albertel 4808: if ( $env{'form.scantron_selectfile'} eq '') {
1.237 albertel 4809: $r->print('<p><font color="red">You have not selected a file that contains the student\'s response data.</font></p>');
4810: }
1.257 albertel 4811: if ( $env{'form.scantron_format'} eq '') {
1.237 albertel 4812: $r->print('<p><font color="red">You have not selected a the format of the student\'s response data.</font></p>');
4813: }
4814: } else {
1.265 www 4815: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 4816: $r->print(<<STUFF);
1.203 albertel 4817: $warning
1.265 www 4818: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 4819: <input type="hidden" name="command" value="scantron_validate" />
4820: STUFF
1.237 albertel 4821: }
1.324 albertel 4822: $r->print("</form><br />".&show_grading_menu_form($symb)."</body></html>");
1.203 albertel 4823: return '';
4824: }
4825:
4826: sub scantron_form_start {
4827: my ($max_bubble)=@_;
4828: my $result= <<SCANTRONFORM;
4829: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 4830: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
4831: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
4832: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 4833: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 4834: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
4835: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
4836: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
4837: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 4838: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 4839: SCANTRONFORM
4840: return $result;
4841: }
4842:
1.157 albertel 4843: sub scantron_validate_file {
4844: my ($r) = @_;
1.324 albertel 4845: my ($symb)=&get_symb($r);
1.157 albertel 4846: if (!$symb) {return '';}
1.324 albertel 4847: my $default_form_data=&defaultFormData($symb);
1.200 albertel 4848:
4849: # do the detection of only doing skipped records first befroe we delete
4850: # them when doing the corrections reset
1.257 albertel 4851: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 4852: &reset_skipping_status();
4853: }
1.257 albertel 4854: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 4855: &remember_current_skipped();
4856: &scantron_remove_file('skipped');
1.257 albertel 4857: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 4858: }
4859:
1.257 albertel 4860: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 4861: &check_for_error($r,&scantron_remove_file('corrected'));
4862: &check_for_error($r,&scantron_remove_file('skipped'));
4863: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 4864: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 4865: }
1.200 albertel 4866:
1.257 albertel 4867: if ($env{'form.scantron_corrections'}) {
1.157 albertel 4868: &scantron_process_corrections($r);
4869: }
1.191 albertel 4870: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 4871: #get the student pick code ready
4872: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 4873: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 4874: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 4875: $r->print($result);
4876:
1.334 albertel 4877: my @validate_phases=( 'sequence',
4878: 'ID',
1.157 albertel 4879: 'CODE',
4880: 'doublebubble',
4881: 'missingbubbles');
1.257 albertel 4882: if (!$env{'form.validatepass'}) {
4883: $env{'form.validatepass'} = 0;
1.157 albertel 4884: }
1.257 albertel 4885: my $currentphase=$env{'form.validatepass'};
1.157 albertel 4886:
4887: my $stop=0;
4888: while (!$stop && $currentphase < scalar(@validate_phases)) {
4889: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
4890: $r->rflush();
4891: my $which="scantron_validate_".$validate_phases[$currentphase];
4892: {
4893: no strict 'refs';
4894: ($stop,$currentphase)=&$which($r,$currentphase);
4895: }
4896: }
4897: if (!$stop) {
1.203 albertel 4898: my $warning=&scantron_warning_screen('Start Grading');
4899: $r->print(<<STUFF);
4900: Validation process complete.<br />
4901: $warning
4902: <input type="submit" name="submit" value="Start Grading" />
4903: <input type="hidden" name="command" value="scantron_process" />
4904: STUFF
4905:
1.157 albertel 4906: } else {
4907: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
4908: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
4909: }
4910: if ($stop) {
1.334 albertel 4911: if ($validate_phases[$currentphase] eq 'sequence') {
4912: $r->print('<input type="submit" name="submit" value="Ignore -> " />');
4913: $r->print(' this error <br />');
4914:
4915: $r->print(" <p>Or click the 'Grading Menu' button to start over.</p>");
4916: } else {
4917: $r->print('<input type="submit" name="submit" value="Continue ->" />');
4918: $r->print(' using corrected info <br />');
4919: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
4920: $r->print(" this scanline saving it for later.");
4921: }
1.157 albertel 4922: }
1.324 albertel 4923: $r->print(" </form><br />".&show_grading_menu_form($symb).
1.157 albertel 4924: "</body></html>");
4925: return '';
4926: }
4927:
1.200 albertel 4928: sub scantron_remove_file {
1.192 albertel 4929: my ($which)=@_;
1.257 albertel 4930: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4931: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4932: my $file='scantron_';
1.200 albertel 4933: if ($which eq 'corrected' || $which eq 'skipped') {
4934: $file.=$which.'_';
1.192 albertel 4935: } else {
4936: return 'refused';
4937: }
1.257 albertel 4938: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 4939: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
4940: }
4941:
4942: sub scantron_remove_scan_data {
1.257 albertel 4943: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4944: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4945: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
4946: my @todelete;
1.257 albertel 4947: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 4948: foreach my $key (@keys) {
4949: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 4950: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 4951: $key=~/remember_skipping/) {
4952: next;
4953: }
1.192 albertel 4954: push(@todelete,$key);
4955: }
4956: }
1.200 albertel 4957: my $result;
1.192 albertel 4958: if (@todelete) {
1.200 albertel 4959: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 4960: }
4961: return $result;
4962: }
4963:
1.157 albertel 4964: sub scantron_getfile {
1.200 albertel 4965: #FIXME really would prefer a scantron directory
1.257 albertel 4966: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4967: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 4968: my $lines;
4969: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4970: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 4971: my %scanlines;
4972: $scanlines{'orig'}=[(split("\n",$lines,-1))];
4973: my $temp=$scanlines{'orig'};
4974: $scanlines{'count'}=$#$temp;
4975:
4976: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4977: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 4978: if ($lines eq '-1') {
4979: $scanlines{'corrected'}=[];
4980: } else {
4981: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
4982: }
4983: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4984: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 4985: if ($lines eq '-1') {
4986: $scanlines{'skipped'}=[];
4987: } else {
4988: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
4989: }
1.175 albertel 4990: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 4991: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
4992: my %scan_data = @tmp;
4993: return (\%scanlines,\%scan_data);
4994: }
4995:
4996: sub lonnet_putfile {
4997: my ($contents,$filename)=@_;
1.257 albertel 4998: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4999: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5000: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 5001: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 5002:
5003: }
5004:
5005: sub scantron_putfile {
5006: my ($scanlines,$scan_data) = @_;
1.200 albertel 5007: #FIXME really would prefer a scantron directory
1.257 albertel 5008: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5009: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 5010: if ($scanlines) {
5011: my $prefix='scantron_';
1.157 albertel 5012: # no need to update orig, shouldn't change
5013: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 5014: # $env{'form.scantron_selectfile'});
1.200 albertel 5015: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
5016: $prefix.'corrected_'.
1.257 albertel 5017: $env{'form.scantron_selectfile'});
1.200 albertel 5018: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
5019: $prefix.'skipped_'.
1.257 albertel 5020: $env{'form.scantron_selectfile'});
1.200 albertel 5021: }
1.175 albertel 5022: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 5023: }
5024:
5025: sub scantron_get_line {
1.200 albertel 5026: my ($scanlines,$scan_data,$i)=@_;
5027: if (&should_be_skipped($scan_data,$i)) { return undef; }
5028: if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 5029: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
5030: return $scanlines->{'orig'}[$i];
5031: }
5032:
1.200 albertel 5033: sub get_todo_count {
5034: my ($scanlines,$scan_data)=@_;
5035: my $count=0;
5036: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5037: my $line=&scantron_get_line($scanlines,$scan_data,$i);
5038: if ($line=~/^[\s\cz]*$/) { next; }
5039: $count++;
5040: }
5041: return $count;
5042: }
5043:
1.157 albertel 5044: sub scantron_put_line {
1.200 albertel 5045: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 5046: if ($skip) {
5047: $scanlines->{'skipped'}[$i]=$newline;
1.200 albertel 5048: &allow_skipping($scan_data,$i);
1.157 albertel 5049: return;
5050: }
5051: $scanlines->{'corrected'}[$i]=$newline;
5052: }
5053:
1.334 albertel 5054: sub scantron_filter_not_exam {
5055: my ($curres)=@_;
5056:
5057: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
5058: # if the user has asked to not have either hidden
5059: # or 'randomout' controlled resources to be graded
5060: # don't include them
5061: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5062: && $curres->randomout) {
5063: return 0;
5064: }
5065: return 1;
5066: }
5067: return 0;
5068: }
5069:
5070: sub scantron_validate_sequence {
5071: my ($r,$currentphase) = @_;
5072:
5073: my $navmap=Apache::lonnavmaps::navmap->new();
5074: my (undef,undef,$sequence)=
5075: &Apache::lonnet::decode_symb($env{'form.selectpage'});
5076:
5077: my $map=$navmap->getResourceByUrl($sequence);
5078:
5079: $r->print('<input type="hidden" name="validate_sequence_exam"
5080: value="ignore" />');
5081: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
5082: my @resources=
5083: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
5084: if (@resources) {
5085: $r->print("<p>".&mt('Some resource in the sequece currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
5086: return (1,$currentphase);
5087: }
5088: }
5089:
5090: return (0,$currentphase+1);
5091: }
5092:
1.157 albertel 5093: sub scantron_validate_ID {
5094: my ($r,$currentphase) = @_;
5095:
5096: #get student info
5097: my $classlist=&Apache::loncoursedata::get_classlist();
5098: my %idmap=&username_to_idmap($classlist);
5099:
5100: #get scantron line setup
1.257 albertel 5101: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5102: my ($scanlines,$scan_data)=&scantron_getfile();
5103:
5104: my %found=('ids'=>{},'usernames'=>{});
5105: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5106: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5107: if ($line=~/^[\s\cz]*$/) { next; }
5108: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5109: $scan_data);
5110: my $id=$$scan_record{'scantron.ID'};
5111: my $found;
5112: foreach my $checkid (keys(%idmap)) {
5113: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
5114: }
5115: if ($found) {
5116: my $username=$idmap{$found};
5117: if ($found{'ids'}{$found}) {
5118: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5119: $line,'duplicateID',$found);
1.194 albertel 5120: return(1,$currentphase);
1.157 albertel 5121: } elsif ($found{'usernames'}{$username}) {
5122: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5123: $line,'duplicateID',$username);
1.194 albertel 5124: return(1,$currentphase);
1.157 albertel 5125: }
1.186 albertel 5126: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 5127: $found{'ids'}{$found}++;
5128: $found{'usernames'}{$username}++;
5129: } else {
5130: if ($id =~ /^\s*$/) {
1.158 albertel 5131: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 5132: if (defined($username) && $found{'usernames'}{$username}) {
5133: &scantron_get_correction($r,$i,$scan_record,
5134: \%scantron_config,
5135: $line,'duplicateID',$username);
1.194 albertel 5136: return(1,$currentphase);
1.157 albertel 5137: } elsif (!defined($username)) {
5138: &scantron_get_correction($r,$i,$scan_record,
5139: \%scantron_config,
5140: $line,'incorrectID');
1.194 albertel 5141: return(1,$currentphase);
1.157 albertel 5142: }
5143: $found{'usernames'}{$username}++;
5144: } else {
5145: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5146: $line,'incorrectID');
1.194 albertel 5147: return(1,$currentphase);
1.157 albertel 5148: }
5149: }
5150: }
5151:
5152: return (0,$currentphase+1);
5153: }
5154:
5155: sub scantron_get_correction {
5156: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
5157:
5158: #FIXME in the case of a duplicated ID the previous line, probaly need
5159: #to show both the current line and the previous one and allow skipping
5160: #the previous one or the current one
5161:
1.161 albertel 5162: $r->print("<p><b>An error was detected ($error)</b>");
1.333 albertel 5163: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.157 albertel 5164: $r->print(" for PaperID <tt>".
5165: $$scan_record{'scantron.PaperID'}."</tt> \n");
5166: } else {
5167: $r->print(" in scanline $i <pre>".
5168: $line."</pre> \n");
5169: }
1.242 albertel 5170: my $message="<p>The ID on the form is <tt>".
5171: $$scan_record{'scantron.ID'}."</tt><br />\n".
5172: "The name on the paper is ".
5173: $$scan_record{'scantron.LastName'}.",".
5174: $$scan_record{'scantron.FirstName'}."</p>";
5175:
1.157 albertel 5176: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
5177: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
5178: if ($error =~ /ID$/) {
1.186 albertel 5179: if ($error eq 'incorrectID') {
1.157 albertel 5180: $r->print("The encoded ID is not in the classlist</p>\n");
5181: } elsif ($error eq 'duplicateID') {
5182: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
5183: }
1.242 albertel 5184: $r->print($message);
1.157 albertel 5185: $r->print("<p>How should I handle this? <br /> \n");
5186: $r->print("\n<ul><li> ");
5187: #FIXME it would be nice if this sent back the user ID and
5188: #could do partial userID matches
5189: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
5190: 'scantron_username','scantron_domain'));
5191: $r->print(": <input type='text' name='scantron_username' value='' />");
5192: $r->print("\n@".
1.257 albertel 5193: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 5194:
5195: $r->print('</li>');
1.186 albertel 5196: } elsif ($error =~ /CODE$/) {
5197: if ($error eq 'incorrectCODE') {
1.187 albertel 5198: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5199: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5200: $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 5201: }
1.224 albertel 5202: $r->print("<p>The CODE on the form is <tt>'".
5203: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5204: $r->print($message);
1.186 albertel 5205: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5206: $r->print("\n<br /> ");
1.194 albertel 5207: my $i=0;
1.273 albertel 5208: if ($error eq 'incorrectCODE'
5209: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5210: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5211: if ($closest > 0) {
5212: foreach my $testcode (@{$closest}) {
5213: my $checked='';
5214: if (!$i) { $checked=' checked="on" '; }
5215: $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' />");
5216: $r->print("\n<br />");
5217: $i++;
5218: }
1.194 albertel 5219: }
5220: }
1.273 albertel 5221: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5222: my $checked; if (!$i) { $checked=' checked="on" '; }
5223: $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>");
5224: $r->print("\n<br />");
5225: }
1.194 albertel 5226:
1.188 albertel 5227: $r->print(<<ENDSCRIPT);
5228: <script type="text/javascript">
5229: function change_radio(field) {
1.190 albertel 5230: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5231: var i;
5232: for (i=0;i<slct.length;i++) {
5233: if (slct[i].value==field) { slct[i].checked=true; }
5234: }
5235: }
5236: </script>
5237: ENDSCRIPT
1.187 albertel 5238: my $href="/adm/pickcode?".
5239: "form=".&Apache::lonnet::escape("scantronupload").
1.257 albertel 5240: "&scantron_format=".&Apache::lonnet::escape($env{'form.scantron_format'}).
5241: "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
1.187 albertel 5242: "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
1.257 albertel 5243: "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
1.332 albertel 5244: if ($env{'form.scantron_CODElist'} =~ /\S/) {
5245: $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')\" />");
5246: $r->print("\n<br />");
5247: }
1.272 albertel 5248: $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 5249: $r->print("\n<br /><br />");
1.157 albertel 5250: } elsif ($error eq 'doublebubble') {
5251: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5252: $r->print('<input type="hidden" name="scantron_questions" value="'.
5253: join(',',@{$arg}).'" />');
1.242 albertel 5254: $r->print($message);
1.157 albertel 5255: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5256: foreach my $question (@{$arg}) {
5257: my $selected=$$scan_record{"scantron.$question.answer"};
5258: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5259: }
5260: } elsif ($error eq 'missingbubble') {
5261: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5262: $r->print($message);
1.157 albertel 5263: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5264: $r->print("Some questions have no scanned bubbles\n");
5265: $r->print('<input type="hidden" name="scantron_questions" value="'.
5266: join(',',@{$arg}).'" />');
5267: foreach my $question (@{$arg}) {
5268: my $selected=$$scan_record{"scantron.$question.answer"};
5269: &scantron_bubble_selector($r,$scan_config,$question);
5270: }
5271: } else {
5272: $r->print("\n<ul>");
5273: }
5274: $r->print("\n</li></ul>");
5275:
5276: }
5277:
5278: sub scantron_bubble_selector {
5279: my ($r,$scan_config,$quest,@selected)=@_;
5280: my $max=$$scan_config{'Qlength'};
1.274 albertel 5281:
5282: my $scmode=$$scan_config{'Qon'};
5283: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5284:
1.157 albertel 5285: my @alphabet=('A'..'Z');
5286: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5287: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5288: $r->print("\n".'<td align="center">');
1.157 albertel 5289: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5290: else { $r->print(' '); }
5291: $r->print('</td>');
5292: }
1.274 albertel 5293: $r->print('</tr><tr>');
1.157 albertel 5294: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5295: $r->print("\n".
5296: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5297: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5298: }
1.272 albertel 5299: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5300: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5301: $r->print('</tr></table>');
5302: }
5303:
1.194 albertel 5304: sub num_matches {
5305: my ($orig,$code) = @_;
5306: my @code=split(//,$code);
5307: my @orig=split(//,$orig);
5308: my $same=0;
5309: for (my $i=0;$i<scalar(@code);$i++) {
5310: if ($code[$i] eq $orig[$i]) { $same++; }
5311: }
5312: return $same;
5313: }
5314:
5315: sub scantron_get_closely_matching_CODEs {
5316: my ($allcodes,$CODE)=@_;
5317: my @CODEs;
5318: foreach my $testcode (sort(keys(%{$allcodes}))) {
5319: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5320: }
5321:
5322: return ($#CODEs,$CODEs[-1]);
5323: }
5324:
5325: sub get_codes {
1.280 foxr 5326: my ($old_name, $cdom, $cnum) = @_;
5327: if (!$old_name) {
5328: $old_name=$env{'form.scantron_CODElist'};
5329: }
5330: if (!$cdom) {
5331: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5332: }
5333: if (!$cnum) {
5334: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5335: }
1.278 albertel 5336: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5337: $cdom,$cnum);
5338: my %allcodes;
5339: if ($result{"type\0$old_name"} eq 'number') {
5340: %allcodes=map {($_,1)} split(',',$result{$old_name});
5341: } else {
5342: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5343: }
1.194 albertel 5344: return %allcodes;
5345: }
5346:
1.157 albertel 5347: sub scantron_validate_CODE {
5348: my ($r,$currentphase) = @_;
1.257 albertel 5349: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5350: if ($scantron_config{'CODElocation'} &&
5351: $scantron_config{'CODEstart'} &&
5352: $scantron_config{'CODElength'}) {
1.257 albertel 5353: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5354: &FIXME_blow_up()
5355: }
5356: } else {
5357: return (0,$currentphase+1);
5358: }
5359:
5360: my %usedCODEs;
5361:
1.194 albertel 5362: my %allcodes=&get_codes();
1.186 albertel 5363:
5364: my ($scanlines,$scan_data)=&scantron_getfile();
5365: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5366: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5367: if ($line=~/^[\s\cz]*$/) { next; }
5368: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5369: $scan_data);
5370: my $CODE=$$scan_record{'scantron.CODE'};
5371: my $error=0;
1.224 albertel 5372: if (!&Apache::lonnet::validCODE($CODE)) {
5373: &scantron_get_correction($r,$i,$scan_record,
5374: \%scantron_config,
5375: $line,'incorrectCODE',\%allcodes);
5376: return(1,$currentphase);
5377: }
1.221 albertel 5378: if (%allcodes && !exists($allcodes{$CODE})
5379: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5380: &scantron_get_correction($r,$i,$scan_record,
5381: \%scantron_config,
1.194 albertel 5382: $line,'incorrectCODE',\%allcodes);
5383: return(1,$currentphase);
1.186 albertel 5384: }
1.214 albertel 5385: if (exists($usedCODEs{$CODE})
1.257 albertel 5386: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5387: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5388: &scantron_get_correction($r,$i,$scan_record,
5389: \%scantron_config,
1.194 albertel 5390: $line,'duplicateCODE',$usedCODEs{$CODE});
5391: return(1,$currentphase);
1.186 albertel 5392: }
1.194 albertel 5393: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5394: }
1.157 albertel 5395: return (0,$currentphase+1);
5396: }
5397:
5398: sub scantron_validate_doublebubble {
5399: my ($r,$currentphase) = @_;
5400: #get student info
5401: my $classlist=&Apache::loncoursedata::get_classlist();
5402: my %idmap=&username_to_idmap($classlist);
5403:
5404: #get scantron line setup
1.257 albertel 5405: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5406: my ($scanlines,$scan_data)=&scantron_getfile();
5407: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5408: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5409: if ($line=~/^[\s\cz]*$/) { next; }
5410: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5411: $scan_data);
5412: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5413: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5414: 'doublebubble',
5415: $$scan_record{'scantron.doubleerror'});
5416: return (1,$currentphase);
5417: }
5418: return (0,$currentphase+1);
5419: }
5420:
1.330 albertel 5421: sub scantron_get_maxbubble {
1.257 albertel 5422: if (defined($env{'form.scantron_maxbubble'}) &&
5423: $env{'form.scantron_maxbubble'}) {
5424: return $env{'form.scantron_maxbubble'};
1.191 albertel 5425: }
1.330 albertel 5426:
1.191 albertel 5427: my $navmap=Apache::lonnavmaps::navmap->new();
5428: my (undef,undef,$sequence)=
1.257 albertel 5429: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 5430:
1.191 albertel 5431: my $map=$navmap->getResourceByUrl($sequence);
5432: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 5433:
5434: &Apache::lonxml::clear_problem_counter();
5435:
1.191 albertel 5436: foreach my $resource (@resources) {
1.330 albertel 5437: my $result=&Apache::lonnet::ssi($resource->src(),
5438: ('symb' => $resource->symb()));
1.191 albertel 5439: }
5440: &Apache::lonnet::delenv('scantron\.');
1.330 albertel 5441: $env{'form.scantron_maxbubble'} =
5442: &Apache::lonxml::get_problem_counter()-1;
5443:
1.257 albertel 5444: return $env{'form.scantron_maxbubble'};
1.191 albertel 5445: }
5446:
1.157 albertel 5447: sub scantron_validate_missingbubbles {
5448: my ($r,$currentphase) = @_;
5449: #get student info
5450: my $classlist=&Apache::loncoursedata::get_classlist();
5451: my %idmap=&username_to_idmap($classlist);
5452:
5453: #get scantron line setup
1.257 albertel 5454: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5455: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5456: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5457: if (!$max_bubble) { $max_bubble=2**31; }
5458: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5459: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5460: if ($line=~/^[\s\cz]*$/) { next; }
5461: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5462: $scan_data);
5463: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5464: my @to_correct;
5465: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5466: if ($missing > $max_bubble) { next; }
5467: push(@to_correct,$missing);
5468: }
5469: if (@to_correct) {
5470: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5471: $line,'missingbubble',\@to_correct);
5472: return (1,$currentphase);
5473: }
5474:
5475: }
5476: return (0,$currentphase+1);
5477: }
5478:
1.82 albertel 5479: sub scantron_process_students {
1.75 albertel 5480: my ($r) = @_;
1.257 albertel 5481: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 5482: my ($symb)=&get_symb($r);
1.81 albertel 5483: if (!$symb) {return '';}
1.324 albertel 5484: my $default_form_data=&defaultFormData($symb);
1.82 albertel 5485:
1.257 albertel 5486: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5487: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5488: my $classlist=&Apache::loncoursedata::get_classlist();
5489: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5490: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5491: my $map=$navmap->getResourceByUrl($sequence);
5492: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5493: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5494: my $result= <<SCANTRONFORM;
1.81 albertel 5495: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5496: <input type="hidden" name="command" value="scantron_configphase" />
5497: $default_form_data
5498: SCANTRONFORM
1.82 albertel 5499: $r->print($result);
5500:
5501: my @delayqueue;
1.140 albertel 5502: my %completedstudents;
5503:
1.200 albertel 5504: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5505: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5506: 'Scantron Progress',$count,
1.195 albertel 5507: 'inline',undef,'scantronupload');
1.140 albertel 5508: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5509: 'Processing first student');
5510: my $start=&Time::HiRes::time();
1.158 albertel 5511: my $i=-1;
1.200 albertel 5512: my ($uname,$udom,$started);
1.157 albertel 5513: while ($i<$scanlines->{'count'}) {
5514: ($uname,$udom)=('','');
5515: $i++;
1.200 albertel 5516: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5517: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5518: if ($started) {
5519: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5520: 'last student');
5521: }
5522: $started=1;
1.157 albertel 5523: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5524: $scan_data);
5525: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5526: \%idmap,$i)) {
5527: &scantron_add_delay(\@delayqueue,$line,
5528: 'Unable to find a student that matches',1);
5529: next;
5530: }
5531: if (exists $completedstudents{$uname}) {
5532: &scantron_add_delay(\@delayqueue,$line,
5533: 'Student '.$uname.' has multiple sheets',2);
5534: next;
5535: }
5536: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 5537:
5538: &Apache::lonxml::clear_problem_counter();
1.157 albertel 5539: &Apache::lonnet::appenv(%$scan_record);
1.161 albertel 5540:
5541: my $i=0;
1.83 albertel 5542: foreach my $resource (@resources) {
1.85 albertel 5543: $i++;
1.193 albertel 5544: my %form=('submitted' =>'scantron',
5545: 'grade_target' =>'grade',
5546: 'grade_username'=>$uname,
5547: 'grade_domain' =>$udom,
1.257 albertel 5548: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5549: 'grade_symb' =>$resource->symb());
5550: if (exists($scan_record->{'scantron.CODE'}) &&
5551: $scan_record->{'scantron.CODE'}) {
5552: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5553: } else {
5554: $form{'CODE'}='';
1.193 albertel 5555: }
5556: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5557: if ($result ne '') {
5558: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5559: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5560: }
1.213 albertel 5561: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5562: }
1.140 albertel 5563: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5564: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5565: } continue {
1.330 albertel 5566: &Apache::lonxml::clear_problem_counter();
1.83 albertel 5567: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5568: }
1.140 albertel 5569: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5570: # my $lasttime = &Time::HiRes::time()-$start;
5571: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5572:
1.200 albertel 5573: $r->print("</form>");
1.324 albertel 5574: $r->print(&show_grading_menu_form($symb));
1.157 albertel 5575: return '';
1.75 albertel 5576: }
1.157 albertel 5577:
5578: sub scantron_upload_scantron_data {
5579: my ($r)=@_;
1.257 albertel 5580: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5581: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5582: 'domainid',
5583: 'coursename');
1.257 albertel 5584: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5585: 'domainid');
1.324 albertel 5586: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.157 albertel 5587: $r->print(<<UPLOAD);
5588: <script type="text/javascript" language="javascript">
5589: function checkUpload(formname) {
5590: if (formname.upfile.value == "") {
5591: alert("Please use the browse button to select a file from your local directory.");
5592: return false;
5593: }
5594: formname.submit();
5595: }
5596: </script>
5597:
5598: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5599: $default_form_data
1.181 albertel 5600: <table>
5601: <tr><td>$select_link </td></tr>
5602: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5603: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5604: <tr><td>Domain: </td><td>$domsel </td></tr>
5605: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5606: </table>
1.157 albertel 5607: <input name='command' value='scantronupload_save' type='hidden' />
5608: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5609: </form>
5610: UPLOAD
5611: return '';
5612: }
5613:
5614: sub scantron_upload_scantron_data_save {
5615: my($r)=@_;
1.324 albertel 5616: my ($symb)=&get_symb($r,1);
1.182 albertel 5617: my $doanotherupload=
5618: '<br /><form action="/adm/grades" method="post">'."\n".
5619: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5620: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5621: '</form>'."\n";
1.257 albertel 5622: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5623: !&Apache::lonnet::allowed('usc',
1.257 albertel 5624: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5625: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5626: if ($symb) {
1.324 albertel 5627: $r->print(&show_grading_menu_form($symb));
1.182 albertel 5628: } else {
5629: $r->print($doanotherupload);
5630: }
1.162 albertel 5631: return '';
5632: }
1.257 albertel 5633: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5634: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5635: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5636: #FIXME
5637: #copied from lonnet::userfileupload()
5638: #make that function able to target a specified course
5639: # Replace Windows backslashes by forward slashes
5640: $fname=~s/\\/\//g;
5641: # Get rid of everything but the actual filename
5642: $fname=~s/^.*\/([^\/]+)$/$1/;
5643: # Replace spaces by underscores
5644: $fname=~s/\s+/\_/g;
5645: # Replace all other weird characters by nothing
5646: $fname=~s/[^\w\.\-]//g;
5647: # See if there is anything left
5648: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5649: my $uploadedfile=$fname;
1.157 albertel 5650: $fname='scantron_orig_'.$fname;
1.257 albertel 5651: if (length($env{'form.upfile'}) < 2) {
5652: $r->print("<font color='red'>Error:</font> 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 5653: } else {
1.275 albertel 5654: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5655: if ($result =~ m|^/uploaded/|) {
1.257 albertel 5656: $r->print("<font color='green'>Success:</font> Successfully uploaded ".(length($env{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
1.210 albertel 5657: } else {
1.257 albertel 5658: $r->print("<font color='red'>Error:</font> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>");
1.183 albertel 5659: }
5660: }
1.174 albertel 5661: if ($symb) {
1.209 ng 5662: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5663: } else {
1.182 albertel 5664: $r->print($doanotherupload);
1.174 albertel 5665: }
1.157 albertel 5666: return '';
5667: }
5668:
1.202 albertel 5669: sub valid_file {
5670: my ($requested_file)=@_;
5671: foreach my $filename (sort(&scantron_filenames())) {
5672: if ($requested_file eq $filename) { return 1; }
5673: }
5674: return 0;
5675: }
5676:
5677: sub scantron_download_scantron_data {
5678: my ($r)=@_;
1.324 albertel 5679: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5680: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5681: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5682: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5683: if (! &valid_file($file)) {
5684: $r->print(<<ERROR);
5685: <p>
5686: The requested file name was invalid.
5687: </p>
5688: ERROR
1.324 albertel 5689: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5690: return;
5691: }
5692: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5693: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5694: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5695: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5696: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5697: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5698: $r->print(<<DOWNLOAD);
5699: <p>
5700: <a href="$orig">Original</a> file as uploaded by the scantron office.
5701: </p>
5702: <p>
5703: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5704: </p>
5705: <p>
5706: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5707: </p>
5708: DOWNLOAD
1.324 albertel 5709: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5710: return '';
5711: }
1.157 albertel 5712:
1.75 albertel 5713: #-------- end of section for handling grading scantron forms -------
5714: #
5715: #-------------------------------------------------------------------
5716:
1.72 ng 5717: #-------------------------- Menu interface -------------------------
5718: #
5719: #--- Show a Grading Menu button - Calls the next routine ---
5720: sub show_grading_menu_form {
1.324 albertel 5721: my ($symb)=@_;
1.125 ng 5722: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 5723: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 5724: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5725: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5726: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5727: '</form>'."\n";
5728: return $result;
5729: }
5730:
1.77 ng 5731: # -- Retrieve choices for grading form
5732: sub savedState {
5733: my %savedState = ();
1.257 albertel 5734: if ($env{'form.saveState'}) {
5735: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5736: my ($key,$value) = split(/=/,$_,2);
5737: $savedState{$key} = $value;
5738: }
5739: }
5740: return \%savedState;
5741: }
1.76 ng 5742:
1.72 ng 5743: #--- Displays the main menu page -------
5744: sub gradingmenu {
5745: my ($request) = @_;
1.324 albertel 5746: my ($symb)=&get_symb($request);
1.72 ng 5747: if (!$symb) {return '';}
1.76 ng 5748: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5749:
5750: $request->print(<<GRADINGMENUJS);
5751: <script type="text/javascript" language="javascript">
1.116 ng 5752: function checkChoice(formname,val,cmdx) {
5753: if (val <= 2) {
5754: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5755: var cmdsave = cmd;
1.116 ng 5756: } else {
5757: cmd = cmdx;
1.118 ng 5758: cmdsave = 'submission';
1.116 ng 5759: }
5760: formname.command.value = cmd;
1.118 ng 5761: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5762: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5763: if (val < 5) formname.submit();
5764: if (val == 5) {
1.72 ng 5765: if (!checkReceiptNo(formname,'notOK')) { return false;}
5766: formname.submit();
5767: }
1.238 albertel 5768: if (val < 7) formname.submit();
1.72 ng 5769: }
5770:
5771: function checkReceiptNo(formname,nospace) {
5772: var receiptNo = formname.receipt.value;
5773: var checkOpt = false;
5774: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5775: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5776: if (checkOpt) {
5777: alert("Please enter a receipt number given by a student in the receipt box.");
5778: formname.receipt.value = "";
5779: formname.receipt.focus();
5780: return false;
5781: }
5782: return true;
5783: }
5784: </script>
5785: GRADINGMENUJS
1.118 ng 5786: &commonJSfunctions($request);
5787: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.324 albertel 5788: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.118 ng 5789: $result.=$table;
1.76 ng 5790: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 5791: my $savedState = &savedState();
1.118 ng 5792: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 5793: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 5794: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 5795: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 5796:
5797: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
5798: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5799: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
5800: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 5801: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 5802: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 5803: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 5804: '<input type="hidden" name="showgrading" value="yes" />'."\n";
5805:
1.326 albertel 5806: $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
5807: '<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 5808: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 5809: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
5810:
1.326 albertel 5811: $result.='<table width="100%" border="0">';
1.116 ng 5812: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 5813: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 5814: if (ref($sections)) {
1.155 albertel 5815: foreach (sort (@$sections)) {
5816: $result.='<option value="'.$_.'" '.
5817: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
5818: }
1.116 ng 5819: }
1.238 albertel 5820: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 5821:
1.167 sakharuk 5822: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 5823:
1.116 ng 5824: $result.='</td></tr>';
5825:
1.288 albertel 5826: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 5827: '<input type="radio" name="radioChoice" value="submission" '.
1.326 albertel 5828: ($saveCmd eq 'submission' ? 'checked' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 5829: '</label> <select name="submitonly">'.
1.145 albertel 5830: '<option value="yes" '.
1.326 albertel 5831: ($saveSub eq 'yes' ? 'selected="on"' : '').' />'.&mt('with submissions').'</option>'.
1.301 albertel 5832: '<option value="queued" '.
1.326 albertel 5833: ($saveSub eq 'queued' ? 'selected="on"' : '').' />'.&mt('in grading queue').'</option>'.
1.145 albertel 5834: '<option value="graded" '.
1.326 albertel 5835: ($saveSub eq 'graded' ? 'selected="on"' : '').' />'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 5836: '<option value="incorrect" '.
1.326 albertel 5837: ($saveSub eq 'incorrect' ? 'selected="on"' : '').' />'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 5838: '<option value="all" '.
1.326 albertel 5839: ($saveSub eq 'all' ? 'selected="on"' : '').' />'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 5840:
1.116 ng 5841: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 5842: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.326 albertel 5843: ($saveCmd eq 'viewgrades' ? 'checked' : '').' /> '.
1.288 albertel 5844: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 5845:
1.118 ng 5846: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 5847: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.326 albertel 5848: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').' /> '.
1.288 albertel 5849: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 5850:
1.116 ng 5851: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 5852: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 5853: '</td></tr></table>'."\n";
5854:
5855: $result.='</td><td valign="top">';
5856:
1.326 albertel 5857: $result.='<table width="100%" border="0">';
1.116 ng 5858: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 5859: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
5860: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 5861:
1.75 albertel 5862: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 5863: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 5864: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 5865:
1.257 albertel 5866: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 5867: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 5868: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
5869: ' '.&mt('receipt').': '.
1.257 albertel 5870: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.326 albertel 5871: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
1.72 ng 5872: '</td></tr>'."\n";
5873: }
1.238 albertel 5874: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5875: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
5876: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 5877: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5878: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
5879: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 5880:
1.116 ng 5881: $result.='</form></td></tr></table>'."\n".
1.72 ng 5882: '</td></tr></table>'."\n".
5883: '</td></tr></table>'."\n";
1.44 ng 5884: return $result;
1.2 albertel 5885: }
5886:
1.285 albertel 5887: sub reset_perm {
5888: undef(%perm);
5889: }
5890:
5891: sub init_perm {
5892: &reset_perm();
1.300 albertel 5893: foreach my $test_perm ('vgr','mgr','opa') {
5894:
5895: my $scope = $env{'request.course.id'};
5896: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
5897:
5898: $scope .= '/'.$env{'request.course.sec'};
5899: if ( $perm{$test_perm}=
5900: &Apache::lonnet::allowed($test_perm,$scope)) {
5901: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
5902: } else {
5903: delete($perm{$test_perm});
5904: }
1.285 albertel 5905: }
5906: }
5907: }
5908:
1.1 albertel 5909: sub handler {
1.41 ng 5910: my $request=$_[0];
1.102 albertel 5911:
1.285 albertel 5912: &reset_perm();
1.257 albertel 5913: if ($env{'browser.mathml'}) {
1.141 www 5914: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 5915: } else {
1.141 www 5916: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 5917: }
5918: $request->send_http_header;
1.44 ng 5919: return '' if $request->header_only;
1.41 ng 5920: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 5921: my $symb=&get_symb($request,1);
1.160 albertel 5922: my @commands=&Apache::loncommon::get_env_multiple('form.command');
5923: my $command=$commands[0];
5924: if ($#commands > 0) {
5925: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
5926: }
1.41 ng 5927: &send_header($request);
1.324 albertel 5928: if ($symb eq '' && $command eq '') {
1.257 albertel 5929: if ($env{'user.adv'}) {
5930: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
5931: ($env{'form.codethree'})) {
5932: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
5933: $env{'form.codethree'};
1.41 ng 5934: my ($tsymb,$tuname,$tudom,$tcrsid)=
5935: &Apache::lonnet::checkin($token);
5936: if ($tsymb) {
1.137 albertel 5937: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 5938: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 5939: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
5940: ('grade_username' => $tuname,
5941: 'grade_domain' => $tudom,
5942: 'grade_courseid' => $tcrsid,
5943: 'grade_symb' => $tsymb)));
1.41 ng 5944: } else {
1.45 ng 5945: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 5946: }
1.41 ng 5947: } else {
1.45 ng 5948: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 5949: }
1.14 www 5950: } else {
1.41 ng 5951: $request->print(&Apache::lonxml::tokeninputfield());
5952: }
5953: }
5954: } else {
1.285 albertel 5955: &init_perm();
1.104 albertel 5956: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 5957: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 5958: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 5959: &pickStudentPage($request);
1.103 albertel 5960: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 5961: &displayPage($request);
1.104 albertel 5962: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 5963: &updateGradeByPage($request);
1.104 albertel 5964: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 5965: &processGroup($request);
1.104 albertel 5966: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 5967: $request->print(&gradingmenu($request));
1.104 albertel 5968: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 5969: $request->print(&viewgrades($request));
1.104 albertel 5970: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 5971: $request->print(&processHandGrade($request));
1.106 albertel 5972: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 5973: $request->print(&editgrades($request));
1.106 albertel 5974: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 5975: $request->print(&verifyreceipt($request));
1.106 albertel 5976: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 5977: $request->print(&upcsvScores_form($request));
1.106 albertel 5978: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 5979: $request->print(&csvupload($request));
1.106 albertel 5980: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 5981: $request->print(&csvuploadmap($request));
1.246 albertel 5982: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 5983: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 5984: $request->print(&csvuploadoptions($request));
1.41 ng 5985: } else {
1.257 albertel 5986: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
5987: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 5988: } else {
1.257 albertel 5989: $env{'form.upfile_associate'} = 'forward';
1.41 ng 5990: }
5991: $request->print(&csvuploadmap($request));
5992: }
1.246 albertel 5993: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
5994: $request->print(&csvuploadassign($request));
1.106 albertel 5995: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 5996: $request->print(&scantron_selectphase($request));
1.203 albertel 5997: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
5998: $request->print(&scantron_do_warning($request));
1.142 albertel 5999: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
6000: $request->print(&scantron_validate_file($request));
1.106 albertel 6001: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 6002: $request->print(&scantron_process_students($request));
1.157 albertel 6003: } elsif ($command eq 'scantronupload' &&
1.257 albertel 6004: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6005: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 6006: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 6007: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 6008: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6009: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 6010: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 6011: } elsif ($command eq 'scantron_download' &&
1.257 albertel 6012: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 6013: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 6014: } elsif ($command) {
1.157 albertel 6015: $request->print("Access Denied ($command)");
1.26 albertel 6016: }
1.2 albertel 6017: }
1.41 ng 6018: &send_footer($request);
1.44 ng 6019: return '';
6020: }
6021:
6022: sub send_header {
6023: my ($request)= @_;
1.340 albertel 6024: &Apache::lontexconvert::init_tth();
1.339 albertel 6025: $request->print(&Apache::loncommon::start_page('Grading'));
1.157 albertel 6026: $request->rflush();
1.44 ng 6027: }
6028:
6029: sub send_footer {
6030: my ($request)= @_;
1.339 albertel 6031: $request->print(&Apache::loncommon::end_page());
1.1 albertel 6032: }
6033:
6034: 1;
6035:
1.13 albertel 6036: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>