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