Annotation of loncom/homework/grades.pm, revision 1.381
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.381 ! albertel 4: # $Id: grades.pm,v 1.380 2006/10/17 20:19:31 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.381 ! albertel 1472: my $checkIcon = '<img alt="'.&mt('Check Mark').
! 1473: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 1474: '/check.gif" height="16" border="0" />';
1475: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1476: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1477: '<font color="red">problem weight assigned by computer</font>');
1478: $wgt = ($wgt > 0 ? $wgt : '1');
1479: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1480: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1481: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.324 albertel 1482: my $display_part=&get_display_part($partid,$symb);
1.270 albertel 1483: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1484: [$partid]);
1485: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1486: if ($last_resets{$partid}) {
1487: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1488: }
1.71 ng 1489: $result.='<table border="0"><tr><td>'.
1.207 albertel 1490: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1491: my $ctr = 0;
1.348 bowersj2 1492: my $thisweight = 0;
1.349 albertel 1493: my $increment = &get_increment();
1.71 ng 1494: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1495: while ($thisweight<=$wgt) {
1.381 ! albertel 1496: $result.= '<td><span style="white-space: nowrap;"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1497: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1498: $thisweight.')" value="'.$thisweight.'" '.
1.381 ! albertel 1499: ($score eq $thisweight ? 'checked':'').' /> '.$thisweight."</label></span></td>\n";
1.71 ng 1500: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1501: $thisweight += $increment;
1.71 ng 1502: $ctr++;
1503: }
1504: $result.='</tr></table>';
1505: $result.='</td><td> <b>or</b> </td>'."\n";
1506: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1507: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1508: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1509: $wgt.')" /></td>'."\n";
1510: $result.='<td>/'.$wgt.' '.$wgtmsg.
1511: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1512: ' </td><td>'."\n";
1513: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1514: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1515: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.381 ! albertel 1516: $result.='<option> </option>'.
1.125 ng 1517: '<option selected="on">excused</option>';
1.71 ng 1518: } else {
1.381 ! albertel 1519: $result.='<option selected="on"> </option>'.
1.125 ng 1520: '<option>excused</option>';
1.71 ng 1521: }
1.125 ng 1522: $result.='<option>reset status</option></select>'."\n";
1.381 ! albertel 1523: $result.=" \n";
1.71 ng 1524: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1525: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1526: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1527: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1528: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1529: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1530: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1531: $aggtries.'" />'."\n";
1.71 ng 1532: $result.='</td></tr></table>'."\n";
1.323 banghart 1533: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1534: return $result;
1535: }
1.322 albertel 1536:
1537: sub handback_box {
1.323 banghart 1538: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1539: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1540: my (@respids);
1.375 albertel 1541: my @part_response_id = &flatten_responseType($responseType);
1542: foreach my $part_response_id (@part_response_id) {
1543: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1544: if ($part eq $partid) {
1.375 albertel 1545: push(@respids,$resp);
1.323 banghart 1546: }
1547: }
1.318 banghart 1548: my $result;
1.323 banghart 1549: foreach my $respid (@respids) {
1.322 albertel 1550: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1551: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1552: next if (!@$files);
1553: my $file_counter = 1;
1.313 banghart 1554: foreach my $file (@$files) {
1.368 banghart 1555: if ($file =~ /\/portfolio\//) {
1556: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1557: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1558: $file_disp = "$name.$ext";
1559: $file = $file_path.$file_disp;
1560: $result.=&mt('Return commented version of [_1] to student.',
1561: '<span class="LC_filename">'.$file_disp.'</span>');
1562: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1563: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.369 banghart 1564: $result.='(File will be uploaded when you click on Save & Next below.)<br />';
1.368 banghart 1565: $file_counter++;
1566: }
1.322 albertel 1567: }
1.313 banghart 1568: }
1.318 banghart 1569: return $result;
1.71 ng 1570: }
1.44 ng 1571:
1.58 albertel 1572: sub show_problem {
1.144 albertel 1573: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
1574: my $rendered;
1.329 albertel 1575: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1576: if ($mode eq 'both' or $mode eq 'text') {
1577: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.257 albertel 1578: $env{'request.course.id'});
1.144 albertel 1579: }
1.58 albertel 1580: if ($removeform) {
1581: $rendered=~s|<form(.*?)>||g;
1582: $rendered=~s|</form>||g;
1.374 albertel 1583: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1584: }
1.144 albertel 1585: my $companswer;
1586: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1587: &Apache::lonxml::restore_problem_counter();
1.144 albertel 1588: $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1.257 albertel 1589: $env{'request.course.id'});
1.144 albertel 1590: }
1.58 albertel 1591: if ($removeform) {
1592: $companswer=~s|<form(.*?)>||g;
1593: $companswer=~s|</form>||g;
1.144 albertel 1594: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1595: }
1596: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1597: $result.='<table border="0" width="100%">';
1.144 albertel 1598: if ($viewon) {
1599: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1600: if ($mode eq 'both' or $mode eq 'text') {
1601: $result.='View of the problem - ';
1602: } else {
1603: $result.='Correct answer: ';
1604: }
1.257 albertel 1605: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1606: }
1607: if ($mode eq 'both') {
1608: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1609: $result.='<b>Correct answer:</b><br />'.$companswer;
1610: } elsif ($mode eq 'text') {
1611: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1612: } elsif ($mode eq 'answer') {
1613: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1614: }
1.58 albertel 1615: $result.='</td></tr></table>';
1616: $result.='</td></tr></table><br />';
1.71 ng 1617: return $result;
1.58 albertel 1618: }
1619:
1.44 ng 1620: # --------------------------- show submissions of a student, option to grade
1621: sub submission {
1622: my ($request,$counter,$total) = @_;
1623:
1.257 albertel 1624: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1625: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1626: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1627: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1628:
1.324 albertel 1629: my $symb = &get_symb($request);
1630: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1631:
1632: if (!&canview($usec)) {
1.116 ng 1633: $request->print('<font color="red">Unable to view requested student.('.
1.222 albertel 1634: $uname.'@'.$udom.' in section '.$usec.' in course id '.
1.257 albertel 1635: $env{'request.course.id'}.')</font>');
1.324 albertel 1636: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1637: return;
1638: }
1639:
1.257 albertel 1640: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1641: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1642: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1643: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 ! albertel 1644: my $checkIcon = '<img alt="'.&mt('Check Mark').
! 1645: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1646: '/check.gif" height="16" border="0" />';
1.41 ng 1647:
1648: # header info
1649: if ($counter == 0) {
1650: &sub_page_js($request);
1.257 albertel 1651: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1652: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1653: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.76 ng 1654:
1.45 ng 1655: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.257 albertel 1656: '<font size=+1> <b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");
1.118 ng 1657:
1.257 albertel 1658: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1659: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1660: $checkIcon.' symbol.'."\n";
1661: $request->print($checkMark);
1662: }
1.41 ng 1663:
1.44 ng 1664: # option to display problem, only once else it cause problems
1665: # with the form later since the problem has a form.
1.257 albertel 1666: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1667: my $mode;
1.257 albertel 1668: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1669: $mode='both';
1.257 albertel 1670: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1671: $mode='text';
1.257 albertel 1672: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1673: $mode='answer';
1674: }
1.329 albertel 1675: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1676: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1677: }
1678:
1.44 ng 1679: # kwclr is the only variable that is guaranteed to be non blank
1680: # if this subroutine has been called once.
1.41 ng 1681: my %keyhash = ();
1.257 albertel 1682: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1683: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1684: $env{'course.'.$env{'request.course.id'}.'.domain'},
1685: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1686:
1.257 albertel 1687: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1688: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1689: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1690: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1691: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1692: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1693: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1694: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1695: }
1.257 albertel 1696: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1697:
1.303 banghart 1698: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1699: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1700: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1701: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1702: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1703: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1704: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1705: '<input type="hidden" name="studentNo" value="" />'."\n".
1706: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1707: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 1708: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1709: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1710: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1711: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.326 albertel 1712: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
1713: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1714: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1715: '<input type="hidden" name="NCT"'.
1.257 albertel 1716: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1717: if ($env{'form.handgrade'} eq 'yes') {
1718: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1719: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1720: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1721: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1722: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1723: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1724: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1725: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1726: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1727: }
1.123 ng 1728: }
1.41 ng 1729:
1730: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1731: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1732: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1733: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1734: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1735: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1736: '" />'."\n".
1737: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1738: $cts++;
1739: }
1740: $request->print($prnmsg);
1.32 ng 1741:
1.257 albertel 1742: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1743: #
1744: # Print out the keyword options line
1745: #
1.41 ng 1746: $request->print(<<KEYWORDS);
1.38 ng 1747: <b>Keyword Options:</b>
1.122 ng 1748: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1749: <a href="#" onMouseDown="javascript:getSel(); return false"
1750: CLASS="page">Paste Selection to List</a>
1751: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1752: KEYWORDS
1.88 www 1753: #
1754: # Load the other essays for similarity check
1755: #
1.324 albertel 1756: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.88 www 1757: my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
1.359 www 1758: $apath=&escape($apath);
1.88 www 1759: $apath=~s/\W/\_/gs;
1760: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1761: }
1762: }
1.44 ng 1763:
1.257 albertel 1764: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1765: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1766: my $mode;
1.257 albertel 1767: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1768: $mode='both';
1.257 albertel 1769: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1770: $mode='text';
1.257 albertel 1771: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1772: $mode='answer';
1773: }
1.329 albertel 1774: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1775: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1776: }
1.144 albertel 1777:
1.257 albertel 1778: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1779: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1780:
1.44 ng 1781: # Display student info
1.41 ng 1782: $request->print(($counter == 0 ? '' : '<br />'));
1.326 albertel 1783: my $result='<table border="0" width="100%"><tr><td bgcolor="#777777">'."\n".
1784: '<table border="0" width="100%"><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1785:
1.257 albertel 1786: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1787: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1788: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1789:
1.118 ng 1790: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1791: my @col_fullnames;
1.56 matthew 1792: my ($classlist,$fullname);
1.257 albertel 1793: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1794: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1795: for (keys (%$handgrade)) {
1.44 ng 1796: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1797: '.maxcollaborators',
1798: $symb,$udom,$uname);
1799: next if ($ncol <= 0);
1800: s/\_/\./g;
1801: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1802: my @goodcollaborators = ();
1803: my @badcollaborators = ();
1804: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1805: $_ =~ s/[\$\^\(\)]//g;
1806: next if ($_ eq '');
1.80 ng 1807: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1808: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1809: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1810: # Doing this grep allows 'fuzzy' specification
1811: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1812: if (! scalar(@Matches)) {
1813: push @badcollaborators,$_;
1814: } else {
1815: push @goodcollaborators, @Matches;
1816: }
1.80 ng 1817: }
1.86 ng 1818: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1819: $result.='<b>Collaborators: </b>';
1.86 ng 1820: foreach (@goodcollaborators) {
1821: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1822: push @col_fullnames, $givenn.' '.$lastname;
1823: $result.=$$fullname{$_}.' ';
1824: }
1.57 matthew 1825: $result.='<br />'."\n";
1.150 albertel 1826: my ($part)=split(/\./,$_);
1.86 ng 1827: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1828: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1829: "\n";
1.86 ng 1830: }
1831: if (scalar(@badcollaborators) > 0) {
1832: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1833: $result.='This student has submitted ';
1834: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1835: $result .= ': '.join(', ',@badcollaborators);
1836: $result .= '</td></tr></table>';
1837: }
1838: if (scalar(@badcollaborators > $ncol)) {
1839: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1840: $result .= 'This student has submitted too many '.
1841: 'collaborators. Maximum is '.$ncol.'.';
1842: $result .= '</td></tr></table>';
1843: }
1.41 ng 1844: }
1845: }
1.44 ng 1846: $request->print($result."\n");
1.33 ng 1847:
1.44 ng 1848: # print student answer/submission
1849: # Options are (1) Handgaded submission only
1850: # (2) Last submission, includes submission that is not handgraded
1851: # (for multi-response type part)
1852: # (3) Last submission plus the parts info
1853: # (4) The whole record for this student
1.257 albertel 1854: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1855: my ($string,$timestamp)= &get_last_submission(\%record);
1856: my $lastsubonly=''.
1857: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1858: $$timestamp)."</td></tr>\n";
1859: if ($$timestamp eq '') {
1860: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1861: } else {
1862: my %seenparts;
1.375 albertel 1863: my @part_response_id = &flatten_responseType($responseType);
1864: foreach my $part (@part_response_id) {
1865: my ($partid,$respid) = @{ $part };
1.324 albertel 1866: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 1867: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1868: if (exists($seenparts{$partid})) { next; }
1869: $seenparts{$partid}=1;
1.207 albertel 1870: my $submitby='<b>Part:</b> '.$display_part.
1871: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1872: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1873: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1874: '\')"; TARGET=_self>'.
1.257 albertel 1875: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1876: $request->print($submitby);
1877: next;
1878: }
1879: my $responsetype = $responseType->{$partid}->{$respid};
1880: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1881: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1882: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1883: ' )</font> '.
1884: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1885: next;
1886: }
1887: foreach (@$string) {
1888: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1.375 albertel 1889: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.151 albertel 1890: my ($ressub,$subval) = split(/:/,$_,2);
1891: # Similarity check
1892: my $similar='';
1.257 albertel 1893: if($env{'form.checkPlag'}){
1.151 albertel 1894: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1895: &most_similar($uname,$udom,$subval);
1896: if ($osim) {
1897: $osim=int($osim*100.0);
1898: $similar="<hr /><h3><font color=\"#FF0000\">Essay".
1899: " is $osim% similar to an essay by ".
1900: &Apache::loncommon::plainname($oname,$odom).
1901: '</font></h3><blockquote><i>'.
1902: &keywords_highlight($oessay).
1903: '</i></blockquote><hr />';
1904: }
1.150 albertel 1905: }
1.151 albertel 1906: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1907: if ($env{'form.lastSub'} eq 'lastonly' ||
1908: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 1909: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 1910: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 1911: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1912: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1913: ' )</font> ';
1.313 banghart 1914: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1915: if (@$files) {
1.232 albertel 1916: $lastsubonly.='<br /><font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.303 banghart 1917: my $file_counter = 0;
1.313 banghart 1918: foreach my $file (@$files) {
1.303 banghart 1919: $file_counter ++;
1.232 albertel 1920: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 1921: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 1922: }
1.236 albertel 1923: $lastsubonly.='<br />';
1.41 ng 1924: }
1.151 albertel 1925: $lastsubonly.='<b>Submitted Answer: </b>'.
1926: &cleanRecord($subval,$responsetype,$symb,$partid,
1927: $respid,\%record,$order);
1928: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1929: }
1930: }
1931: }
1.151 albertel 1932: }
1933: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1934: $request->print($lastsubonly);
1.257 albertel 1935: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 1936: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 1937: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1938: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1939: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1940: $env{'request.course.id'},
1.44 ng 1941: $last,'.submission',
1942: 'Apache::grades::keywords_highlight'));
1.41 ng 1943: }
1.120 ng 1944:
1.121 ng 1945: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1946: .$udom.'" />'."\n");
1.41 ng 1947:
1.44 ng 1948: # return if view submission with no grading option
1.257 albertel 1949: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 1950: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 1951: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1952: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 1953: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 1954: if (($env{'form.command'} eq 'submission') ||
1955: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 1956: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 1957: }
1.180 albertel 1958: $request->print($toGrade);
1.41 ng 1959: return;
1.180 albertel 1960: } else {
1961: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 1962: }
1.33 ng 1963:
1.121 ng 1964: # essay grading message center
1.257 albertel 1965: if ($env{'form.handgrade'} eq 'yes') {
1966: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 1967: my $msgfor = $givenn.' '.$lastname;
1968: if (scalar(@col_fullnames) > 0) {
1969: my $lastone = pop @col_fullnames;
1970: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1971: }
1972: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 1973: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1974: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
1975: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 1976: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.350 albertel 1977: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1978: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 1979: '<img src="'.$request->dir_config('lonIconsURL').
1980: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 1981: '<br /> ('.
1982: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 1983: $request->print($result);
1.118 ng 1984: }
1.300 albertel 1985: if ($perm{'vgr'}) {
1.297 www 1986: $request->print('<br />'.
1.300 albertel 1987: &Apache::loncommon::track_student_link(&mt('View recent activity'),
1988: $uname,$udom,'check'));
1.297 www 1989: }
1.300 albertel 1990: if ($perm{'opa'}) {
1.297 www 1991: $request->print('<br />'.
1.300 albertel 1992: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
1993: $uname,$udom,$symb,'check'));
1.297 www 1994: }
1.41 ng 1995:
1996: my %seen = ();
1997: my @partlist;
1.129 ng 1998: my @gradePartRespid;
1.375 albertel 1999: my @part_response_id = &flatten_responseType($responseType);
2000: foreach my $part_response_id (@part_response_id) {
2001: my ($partid,$respid) = @{ $part_response_id };
2002: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2003: next if ($seen{$partid} > 0);
1.41 ng 2004: $seen{$partid}++;
1.317 banghart 2005: next if ($$handgrade{$part_resp} =~ /:no$/ && $env{'form.lastSub'} =~ /^(hdgrade)$/);
1.41 ng 2006: push @partlist,$partid;
1.129 ng 2007: push @gradePartRespid,$partid.'.'.$respid;
1.322 albertel 2008: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2009: }
1.45 ng 2010: $result='<input type="hidden" name="partlist'.$counter.
2011: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2012: $result.='<input type="hidden" name="gradePartRespid'.
2013: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2014: my $ctr = 0;
2015: while ($ctr < scalar(@partlist)) {
2016: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2017: $partlist[$ctr].'" />'."\n";
2018: $ctr++;
2019: }
2020: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 2021:
2022: # print end of form
2023: if ($counter == $total) {
1.297 www 2024: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 2025: $endform.='<input type="button" value="Save & Next" '.
2026: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
2027: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
2028: my $ntstu ='<select name="NTSTU">'.
2029: '<option>1</option><option>2</option>'.
2030: '<option>3</option><option>5</option>'.
2031: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2032: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 2033: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
2034: $endform.=$ntstu.'student(s) ';
1.126 ng 2035: $endform.='<input type="button" value="Previous" '.
2036: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
2037: '<input type="button" value="Next" '.
2038: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
2039: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.349 albertel 2040: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2041: "' name='increment' />";
1.45 ng 2042: $endform.='</td><tr></table></form>';
1.324 albertel 2043: $endform.=&show_grading_menu_form($symb);
1.41 ng 2044: $request->print($endform);
2045: }
2046: return '';
1.38 ng 2047: }
2048:
1.44 ng 2049: #--- Retrieve the last submission for all the parts
1.38 ng 2050: sub get_last_submission {
1.119 ng 2051: my ($returnhash)=@_;
1.46 ng 2052: my (@string,$timestamp);
1.119 ng 2053: if ($$returnhash{'version'}) {
1.46 ng 2054: my %lasthash=();
2055: my ($version);
1.119 ng 2056: for ($version=1;$version<=$$returnhash{'version'};$version++) {
2057: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
2058: $lasthash{$_}=$$returnhash{$version.':'.$_};
2059: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2060: }
2061: }
2062: foreach ((keys %lasthash)) {
2063: if ($_ =~ /\.submission$/) {
2064: my ($partid,$foo) = split(/submission$/,$_);
2065: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
2066: '<font color="red">Draft Copy</font> ' : '';
2067: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 2068: }
2069: }
2070: }
1.125 ng 2071: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 2072: return \@string,\$timestamp;
1.38 ng 2073: }
1.35 ng 2074:
1.44 ng 2075: #--- High light keywords, with style choosen by user.
1.38 ng 2076: sub keywords_highlight {
1.44 ng 2077: my $string = shift;
1.257 albertel 2078: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2079: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2080: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2081: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.41 ng 2082: foreach (@keylist) {
1.257 albertel 2083: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 2084: }
2085: return $string;
1.38 ng 2086: }
1.36 ng 2087:
1.44 ng 2088: #--- Called from submission routine
1.38 ng 2089: sub processHandGrade {
1.41 ng 2090: my ($request) = shift;
1.324 albertel 2091: my $symb = &get_symb($request);
2092: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2093: my $button = $env{'form.gradeOpt'};
2094: my $ngrade = $env{'form.NCT'};
2095: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2096: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2097: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2098:
1.44 ng 2099: if ($button eq 'Save & Next') {
2100: my $ctr = 0;
2101: while ($ctr < $ngrade) {
1.257 albertel 2102: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2103: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2104: if ($errorflag eq 'no_score') {
2105: $ctr++;
2106: next;
2107: }
1.104 albertel 2108: if ($errorflag eq 'not_allowed') {
2109: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
2110: $ctr++;
2111: next;
2112: }
1.257 albertel 2113: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2114: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 2115: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2116: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2117: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.362 albertel 2118: $subject.=' ['.&Apache::lonnet::declutter($url).']';
1.44 ng 2119: my (@msgnum) = split(/,/,$includemsg);
2120: foreach (@msgnum) {
1.257 albertel 2121: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2122: }
1.80 ng 2123: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2124: if ($env{'form.withgrades'.$ctr}) {
2125: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
2126: $message.=" for <a href=\"".
1.80 ng 2127: &Apache::lonnet::clutter($url).
1.257 albertel 2128: "?symb=$symb\">$env{'form.probTitle'}</a>";
1.298 www 2129: }
1.324 albertel 2130: $msgstatus = &Apache::lonmsg::user_normal_msg($uname,$udom,
1.362 albertel 2131: $subject,
2132: $message);
1.296 www 2133: $request->print('<br />'.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '.
2134: $msgstatus);
1.44 ng 2135: }
1.257 albertel 2136: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2137: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2138: foreach my $collabstr (@collabstrs) {
2139: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2140: foreach my $collaborator (@collaborators) {
1.150 albertel 2141: my ($errorflag,$pts,$wgt) =
1.324 albertel 2142: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2143: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2144: if ($errorflag eq 'not_allowed') {
1.362 albertel 2145: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2146: next;
2147: } else {
2148: if ($message ne '') {
1.362 albertel 2149: $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message);
1.150 albertel 2150: }
1.104 albertel 2151: }
1.44 ng 2152: }
2153: }
2154: }
2155: $ctr++;
2156: }
2157: }
2158:
1.257 albertel 2159: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2160: # Keywords sorted in alphabatical order
1.257 albertel 2161: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2162: my %keyhash = ();
1.257 albertel 2163: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2164: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2165: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2166: $env{'form.keywords'} = join(' ',@keywords);
2167: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2168: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2169: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2170: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2171: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2172:
2173: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2174: # New messages are saved in env for the next student.
1.119 ng 2175: # All messages are saved in nohist_handgrade.db
2176: my ($ctr,$idx) = (1,1);
1.257 albertel 2177: while ($ctr <= $env{'form.savemsgN'}) {
2178: if ($env{'form.savemsg'.$ctr} ne '') {
2179: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2180: $idx++;
2181: }
2182: $ctr++;
1.41 ng 2183: }
1.119 ng 2184: $ctr = 0;
2185: while ($ctr < $ngrade) {
1.257 albertel 2186: if ($env{'form.newmsg'.$ctr} ne '') {
2187: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2188: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2189: $idx++;
2190: }
2191: $ctr++;
1.41 ng 2192: }
1.257 albertel 2193: $env{'form.savemsgN'} = --$idx;
2194: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2195: my $putresult = &Apache::lonnet::put
1.301 albertel 2196: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2197: }
1.44 ng 2198: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2199: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2200: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2201: my ($ctr,$total) = (0,0);
2202: while ($ctr < $ngrade) {
1.257 albertel 2203: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2204: $ctr++;
2205: }
1.257 albertel 2206: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2207: $ctr = 0;
2208: while ($ctr < $total) {
1.257 albertel 2209: my $processUser = $env{'form.unamedom'.$ctr};
2210: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2211: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2212: &submission($request,$ctr,$total-1);
1.41 ng 2213: $ctr++;
2214: }
2215: return '';
2216: }
1.36 ng 2217:
1.121 ng 2218: # Go directly to grade student - from submission or link from chart page
1.120 ng 2219: if ($button eq 'Grade Student') {
1.324 albertel 2220: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2221: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2222: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2223: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2224: &submission($request,0,0);
2225: return '';
2226: }
2227:
1.44 ng 2228: # Get the next/previous one or group of students
1.257 albertel 2229: my $firststu = $env{'form.unamedom0'};
2230: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2231: my $ctr = 2;
1.41 ng 2232: while ($laststu eq '') {
1.257 albertel 2233: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2234: $ctr++;
2235: $laststu = $firststu if ($ctr > $ngrade);
2236: }
1.44 ng 2237:
1.41 ng 2238: my (@parsedlist,@nextlist);
2239: my ($nextflg) = 0;
1.294 albertel 2240: foreach (sort
2241: {
2242: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2243: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2244: }
2245: return $a cmp $b;
2246: } (keys(%$fullname))) {
1.41 ng 2247: if ($nextflg == 1 && $button =~ /Next$/) {
2248: push @parsedlist,$_;
2249: }
2250: $nextflg = 1 if ($_ eq $laststu);
2251: if ($button eq 'Previous') {
2252: last if ($_ eq $firststu);
2253: push @parsedlist,$_;
2254: }
2255: }
2256: $ctr = 0;
2257: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2258: my ($partlist) = &response_type($symb);
1.41 ng 2259: foreach my $student (@parsedlist) {
1.257 albertel 2260: my $submitonly=$env{'form.submitonly'};
1.41 ng 2261: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2262:
2263: if ($submitonly eq 'queued') {
2264: my %queue_status =
2265: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2266: $udom,$uname);
2267: next if (!defined($queue_status{'gradingqueue'}));
2268: }
2269:
1.156 albertel 2270: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2271: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2272: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2273: my $submitted = 0;
1.248 albertel 2274: my $ungraded = 0;
2275: my $incorrect = 0;
1.145 albertel 2276: foreach (keys(%status)) {
2277: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2278: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2279: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2280: my ($foo,$partid,$foo1) = split(/\./,$_);
2281: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2282: $submitted = 0;
2283: }
1.41 ng 2284: }
1.156 albertel 2285: next if (!$submitted && ($submitonly eq 'yes' ||
2286: $submitonly eq 'incorrect' ||
2287: $submitonly eq 'graded'));
1.248 albertel 2288: next if (!$ungraded && ($submitonly eq 'graded'));
2289: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2290: }
2291: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2292: last if ($ctr == $ntstu);
1.41 ng 2293: $ctr++;
2294: }
1.36 ng 2295:
1.41 ng 2296: $ctr = 0;
2297: my $total = scalar(@nextlist)-1;
1.39 ng 2298:
1.41 ng 2299: foreach (sort @nextlist) {
2300: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2301: $env{'form.student'} = $uname;
2302: $env{'form.userdom'} = $udom;
2303: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2304: &submission($request,$ctr,$total);
2305: $ctr++;
2306: }
2307: if ($total < 0) {
2308: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
2309: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2310: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.324 albertel 2311: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2312: $request->print($the_end);
2313: }
2314: return '';
1.38 ng 2315: }
1.36 ng 2316:
1.44 ng 2317: #---- Save the score and award for each student, if changed
1.38 ng 2318: sub saveHandGrade {
1.324 albertel 2319: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2320: my @version_parts;
1.104 albertel 2321: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2322: $env{'request.course.id'});
1.104 albertel 2323: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2324: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2325: my @parts_graded;
1.77 ng 2326: my %newrecord = ();
2327: my ($pts,$wgt) = ('','');
1.269 raeburn 2328: my %aggregate = ();
2329: my $aggregateflag = 0;
1.301 albertel 2330: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2331: foreach my $new_part (@parts) {
1.337 banghart 2332: #collaborator ($submi may vary for different parts
1.259 banghart 2333: if ($submitter && $new_part ne $part) { next; }
2334: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2335: if ($dropMenu eq 'excused') {
1.259 banghart 2336: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2337: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2338: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2339: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2340: }
1.364 banghart 2341: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2342: }
1.125 ng 2343: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2344: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2345: foreach my $key (keys (%record)) {
1.259 banghart 2346: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2347: }
1.259 banghart 2348: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2349: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2350: my $totaltries = $record{'resource.'.$part.'.tries'};
2351:
2352: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2353: [$new_part]);
2354: my $aggtries =$totaltries;
1.269 raeburn 2355: if ($last_resets{$new_part}) {
1.270 albertel 2356: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2357: $new_part);
1.269 raeburn 2358: }
1.270 albertel 2359:
2360: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2361: if ($aggtries > 0) {
1.327 albertel 2362: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2363: $aggregateflag = 1;
2364: }
1.125 ng 2365: } elsif ($dropMenu eq '') {
1.259 banghart 2366: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2367: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2368: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2369: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2370: next;
2371: }
1.259 banghart 2372: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2373: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2374: my $partial= $pts/$wgt;
1.259 banghart 2375: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2376: #do not update score for part if not changed.
1.346 banghart 2377: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2378: next;
1.251 banghart 2379: } else {
1.259 banghart 2380: push @parts_graded, $new_part;
1.153 albertel 2381: }
1.259 banghart 2382: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2383: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2384: }
1.259 banghart 2385: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2386: if ($partial == 0) {
1.153 albertel 2387: if ($record{$reckey} ne 'incorrect_by_override') {
2388: $newrecord{$reckey} = 'incorrect_by_override';
2389: }
1.41 ng 2390: } else {
1.153 albertel 2391: if ($record{$reckey} ne 'correct_by_override') {
2392: $newrecord{$reckey} = 'correct_by_override';
2393: }
2394: }
2395: if ($submitter &&
1.259 banghart 2396: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2397: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2398: }
1.259 banghart 2399: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2400: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2401: }
1.259 banghart 2402: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2403: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2404: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2405: $dropMenu eq 'reset status')
2406: {
1.342 banghart 2407: push (@version_parts,$new_part);
1.259 banghart 2408: }
1.41 ng 2409: }
1.301 albertel 2410: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2411: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2412:
1.344 albertel 2413: if (%newrecord) {
2414: if (@version_parts) {
1.364 banghart 2415: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2416: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2417: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2418: foreach my $new_part (@version_parts) {
2419: &handback_files($request,$symb,$stuname,$domain,$newflg,
2420: $new_part,\%newrecord);
2421: }
1.259 banghart 2422: }
1.44 ng 2423: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2424: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2425: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2426: $cdom,$cnum,$domain,$stuname);
1.41 ng 2427: }
1.269 raeburn 2428: if ($aggregateflag) {
2429: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2430: $cdom,$cnum);
1.269 raeburn 2431: }
1.301 albertel 2432: return ('',$pts,$wgt);
1.36 ng 2433: }
1.322 albertel 2434:
1.380 albertel 2435: sub check_and_remove_from_queue {
2436: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2437: my @ungraded_parts;
2438: foreach my $part (@{$parts}) {
2439: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2440: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2441: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2442: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2443: ) {
2444: push(@ungraded_parts, $part);
2445: }
2446: }
2447: if ( !@ungraded_parts ) {
2448: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2449: $cnum,$domain,$stuname);
2450: }
2451: }
2452:
1.337 banghart 2453: sub handback_files {
2454: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.359 www 2455: my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
2456: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2457:
2458: my @part_response_id = &flatten_responseType($responseType);
2459: foreach my $part_response_id (@part_response_id) {
2460: my ($part_id,$resp_id) = @{ $part_response_id };
2461: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2462: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2463: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2464: my $file_counter = 1;
1.367 albertel 2465: my $file_msg;
1.337 banghart 2466: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2467: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2468: my ($directory,$answer_file) =
2469: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2470: my ($answer_name,$answer_ver,$answer_ext) =
2471: &file_name_version_ext($answer_file);
1.355 banghart 2472: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.341 banghart 2473: my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
1.338 banghart 2474: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2475: # fix file name
2476: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2477: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2478: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2479: $save_file_name);
1.337 banghart 2480: if ($result !~ m|^/uploaded/|) {
2481: $request->print('<font color="red"> An errror occured ('.$result.
1.355 banghart 2482: ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'</font><br />');
1.356 banghart 2483: } else {
1.360 banghart 2484: # mark the file as read only
2485: my @files = ($save_file_name);
1.372 albertel 2486: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2487: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2488: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2489: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2490: }
2491: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2492: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2493:
1.337 banghart 2494: }
2495: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2496: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2497: $file_counter++;
2498: }
1.367 albertel 2499: my $subject = "File Handed Back by Instructor ";
2500: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2501: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2502: $message .= ' The returned file(s) are named: '. $file_msg;
2503: $message .= " and can be found in your portfolio space.";
2504: my $url = (&Apache::lonnet::decode_symb($symb))[2];
2505: $url = &Apache::lonnet::declutter($url);
2506: my $msgstatus = &Apache::lonmsg::user_normal_msg($stuname,$domain,
2507: $subject.' (File Returned) ['.$url.']',$message);
2508:
1.337 banghart 2509: }
2510: }
1.338 banghart 2511: return;
1.337 banghart 2512: }
2513:
1.313 banghart 2514: sub get_submitted_files {
2515: my ($udom,$uname,$partid,$respid,$record) = @_;
2516: my @files;
2517: if ($$record{"resource.$partid.$respid.portfiles"}) {
2518: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2519: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2520: push(@files,$file_url.$file);
2521: }
2522: }
2523: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2524: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2525: }
2526: return (\@files);
2527: }
1.322 albertel 2528:
1.269 raeburn 2529: # ----------- Provides number of tries since last reset.
2530: sub get_num_tries {
2531: my ($record,$last_reset,$part) = @_;
2532: my $timestamp = '';
2533: my $num_tries = 0;
2534: if ($$record{'version'}) {
2535: for (my $version=$$record{'version'};$version>=1;$version--) {
2536: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2537: $timestamp = $$record{$version.':timestamp'};
2538: if ($timestamp > $last_reset) {
2539: $num_tries ++;
2540: } else {
2541: last;
2542: }
2543: }
2544: }
2545: }
2546: return $num_tries;
2547: }
2548:
2549: # ----------- Determine decrements required in aggregate totals
2550: sub decrement_aggs {
2551: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2552: my %decrement = (
2553: attempts => 0,
2554: users => 0,
2555: correct => 0
2556: );
2557: $decrement{'attempts'} = $aggtries;
2558: if ($solvedstatus =~ /^correct/) {
2559: $decrement{'correct'} = 1;
2560: }
2561: if ($aggtries == $totaltries) {
2562: $decrement{'users'} = 1;
2563: }
2564: foreach my $type (keys (%decrement)) {
2565: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2566: }
2567: return;
2568: }
2569:
2570: # ----------- Determine timestamps for last reset of aggregate totals for parts
2571: sub get_last_resets {
1.270 albertel 2572: my ($symb,$courseid,$partids) =@_;
2573: my %last_resets;
1.269 raeburn 2574: my $cdom = $env{'course.'.$courseid.'.domain'};
2575: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2576: my @keys;
2577: foreach my $part (@{$partids}) {
2578: push(@keys,"$symb\0$part\0resettime");
2579: }
2580: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2581: $cdom,$cname);
2582: foreach my $part (@{$partids}) {
2583: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2584: }
1.270 albertel 2585: return %last_resets;
1.269 raeburn 2586: }
2587:
1.251 banghart 2588: # ----------- Handles creating versions for portfolio files as answers
2589: sub version_portfiles {
1.343 banghart 2590: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2591: my $version_parts = join('|',@$v_flag);
1.343 banghart 2592: my @returned_keys;
1.255 banghart 2593: my $parts = join('|', @$parts_graded);
1.359 www 2594: my $portfolio_root = &propath($domain,$stu_name).
2595: '/userfiles/portfolio';
1.277 albertel 2596: foreach my $key (keys(%$record)) {
1.259 banghart 2597: my $new_portfiles;
1.263 banghart 2598: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2599: my @versioned_portfiles;
1.367 albertel 2600: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2601: foreach my $file (@portfiles) {
1.306 banghart 2602: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2603: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2604: my ($answer_name,$answer_ver,$answer_ext) =
2605: &file_name_version_ext($answer_file);
1.306 banghart 2606: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.342 banghart 2607: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2608: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2609: if ($new_answer ne 'problem getting file') {
1.342 banghart 2610: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2611: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2612: [$directory.$new_answer],
1.306 banghart 2613: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2614: }
1.252 banghart 2615: }
1.343 banghart 2616: $$record{$key} = join(',',@versioned_portfiles);
2617: push(@returned_keys,$key);
1.251 banghart 2618: }
2619: }
1.343 banghart 2620: return (@returned_keys);
1.305 banghart 2621: }
2622:
1.307 banghart 2623: sub get_next_version {
1.341 banghart 2624: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2625: my $version;
2626: foreach my $row (@$dir_list) {
2627: my ($file) = split(/\&/,$row,2);
2628: my ($file_name,$file_version,$file_ext) =
2629: &file_name_version_ext($file);
2630: if (($file_name eq $answer_name) &&
2631: ($file_ext eq $answer_ext)) {
2632: # gets here if filename and extension match, regardless of version
2633: if ($file_version ne '') {
2634: # a versioned file is found so save it for later
2635: if ($file_version > $version) {
2636: $version = $file_version;
2637: }
2638: }
2639: }
2640: }
2641: $version ++;
2642: return($version);
2643: }
2644:
1.305 banghart 2645: sub version_selected_portfile {
1.306 banghart 2646: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2647: my ($answer_name,$answer_ver,$answer_ext) =
2648: &file_name_version_ext($file_name);
2649: my $new_answer;
2650: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2651: if($env{'form.copy'} eq '-1') {
2652: &Apache::lonnet::logthis('problem getting file '.$file_name);
2653: $new_answer = 'problem getting file';
2654: } else {
2655: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2656: my $copy_result = &Apache::lonnet::finishuserfileupload(
2657: $stu_name,$domain,'copy',
2658: '/portfolio'.$directory.$new_answer);
2659: }
2660: return ($new_answer);
1.251 banghart 2661: }
2662:
1.304 albertel 2663: sub file_name_version_ext {
2664: my ($file)=@_;
2665: my @file_parts = split(/\./, $file);
2666: my ($name,$version,$ext);
2667: if (@file_parts > 1) {
2668: $ext=pop(@file_parts);
2669: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2670: $version=pop(@file_parts);
2671: }
2672: $name=join('.',@file_parts);
2673: } else {
2674: $name=join('.',@file_parts);
2675: }
2676: return($name,$version,$ext);
2677: }
2678:
1.44 ng 2679: #--------------------------------------------------------------------------------------
2680: #
2681: #-------------------------- Next few routines handles grading by section or whole class
2682: #
2683: #--- Javascript to handle grading by section or whole class
1.42 ng 2684: sub viewgrades_js {
2685: my ($request) = shift;
2686:
1.41 ng 2687: $request->print(<<VIEWJAVASCRIPT);
2688: <script type="text/javascript" language="javascript">
1.45 ng 2689: function writePoint(partid,weight,point) {
1.125 ng 2690: var radioButton = document.classgrade["RADVAL_"+partid];
2691: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2692: if (point == "textval") {
1.125 ng 2693: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2694: if (isNaN(point) || parseFloat(point) < 0) {
2695: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2696: var resetbox = false;
2697: for (var i=0; i<radioButton.length; i++) {
2698: if (radioButton[i].checked) {
2699: textbox.value = i;
2700: resetbox = true;
2701: }
2702: }
2703: if (!resetbox) {
2704: textbox.value = "";
2705: }
2706: return;
2707: }
1.109 matthew 2708: if (parseFloat(point) > parseFloat(weight)) {
2709: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2710: ") greater than the weight for the part. Accept?");
2711: if (resp == false) {
2712: textbox.value = "";
2713: return;
2714: }
2715: }
1.42 ng 2716: for (var i=0; i<radioButton.length; i++) {
2717: radioButton[i].checked=false;
1.109 matthew 2718: if (parseFloat(point) == i) {
1.42 ng 2719: radioButton[i].checked=true;
2720: }
2721: }
1.41 ng 2722:
1.42 ng 2723: } else {
1.125 ng 2724: textbox.value = parseFloat(point);
1.42 ng 2725: }
1.41 ng 2726: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2727: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2728: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2729: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2730: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2731: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2732: if (saveval != "correct") {
2733: scorename.value = point;
1.43 ng 2734: if (selname[0].selected != true) {
2735: selname[0].selected = true;
2736: }
1.42 ng 2737: }
2738: }
1.125 ng 2739: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2740: }
2741:
2742: function writeRadText(partid,weight) {
1.125 ng 2743: var selval = document.classgrade["SELVAL_"+partid];
2744: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2745: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2746: var textbox = document.classgrade["TEXTVAL_"+partid];
2747: if (selval[1].selected || selval[2].selected) {
1.42 ng 2748: for (var i=0; i<radioButton.length; i++) {
2749: radioButton[i].checked=false;
2750:
2751: }
2752: textbox.value = "";
2753:
2754: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2755: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2756: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2757: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2758: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2759: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2760: if ((saveval != "correct") || override) {
1.42 ng 2761: scorename.value = "";
1.125 ng 2762: if (selval[1].selected) {
2763: selname[1].selected = true;
2764: } else {
2765: selname[2].selected = true;
2766: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2767: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2768: }
1.42 ng 2769: }
2770: }
1.43 ng 2771: } else {
2772: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2773: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2774: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2775: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2776: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2777: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2778: if ((saveval != "correct") || override) {
1.125 ng 2779: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2780: selname[0].selected = true;
2781: }
2782: }
2783: }
1.42 ng 2784: }
2785:
2786: function changeSelect(partid,user) {
1.125 ng 2787: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2788: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2789: var point = textbox.value;
1.125 ng 2790: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2791:
1.109 matthew 2792: if (isNaN(point) || parseFloat(point) < 0) {
2793: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2794: textbox.value = "";
2795: return;
2796: }
1.109 matthew 2797: if (parseFloat(point) > parseFloat(weight)) {
2798: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2799: ") greater than the weight of the part. Accept?");
2800: if (resp == false) {
2801: textbox.value = "";
2802: return;
2803: }
2804: }
1.42 ng 2805: selval[0].selected = true;
2806: }
2807:
2808: function changeOneScore(partid,user) {
1.125 ng 2809: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2810: if (selval[1].selected || selval[2].selected) {
2811: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2812: if (selval[2].selected) {
2813: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2814: }
1.269 raeburn 2815: }
1.42 ng 2816: }
2817:
2818: function resetEntry(numpart) {
2819: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2820: var partid = document.classgrade["partid_"+ctpart].value;
2821: var radioButton = document.classgrade["RADVAL_"+partid];
2822: var textbox = document.classgrade["TEXTVAL_"+partid];
2823: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2824: for (var i=0; i<radioButton.length; i++) {
2825: radioButton[i].checked=false;
2826:
2827: }
2828: textbox.value = "";
2829: selval[0].selected = true;
2830:
2831: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2832: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2833: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2834: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2835: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2836: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2837: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2838: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2839: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2840: if (saveselval == "excused") {
1.43 ng 2841: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2842: } else {
1.43 ng 2843: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2844: }
2845: }
1.41 ng 2846: }
1.42 ng 2847: }
2848:
1.41 ng 2849: </script>
2850: VIEWJAVASCRIPT
1.42 ng 2851: }
2852:
1.44 ng 2853: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2854: sub viewgrades {
2855: my ($request) = shift;
2856: &viewgrades_js($request);
1.41 ng 2857:
1.324 albertel 2858: my ($symb) = &get_symb($request);
1.168 albertel 2859: #need to make sure we have the correct data for later EXT calls,
2860: #thus invalidate the cache
2861: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2862: $env{'course.'.$env{'request.course.id'}.'.num'},
2863: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2864: &Apache::lonnet::clear_EXT_cache_status();
2865:
1.167 sakharuk 2866: my $result='<h3><font color="#339933">'.&mt('Manual Grading').'</font></h3>';
1.257 albertel 2867: $result.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n";
1.41 ng 2868:
2869: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 2870: $result.=&jscriptNform($symb);
1.41 ng 2871:
1.44 ng 2872: #beginning of class grading form
1.41 ng 2873: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2874: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.38 ng 2875: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2876: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2877: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2878: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2879: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2880:
1.126 ng 2881: my $sectionClass;
1.257 albertel 2882: if ($env{'form.section'} eq 'all') {
1.126 ng 2883: $sectionClass='Class </h3>';
1.257 albertel 2884: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2885: $sectionClass='Students in no Section </h3>';
1.52 albertel 2886: } else {
1.257 albertel 2887: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2888: }
1.126 ng 2889: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2890: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2891: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2892: #radio buttons/text box for assigning points for a section or class.
2893: #handles different parts of a problem
1.375 albertel 2894: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 2895: my %weight = ();
2896: my $ctsparts = 0;
1.41 ng 2897: $result.='<table border="0">';
1.45 ng 2898: my %seen = ();
1.375 albertel 2899: my @part_response_id = &flatten_responseType($responseType);
2900: foreach my $part_response_id (@part_response_id) {
2901: my ($partid,$respid) = @{ $part_response_id };
2902: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 2903: next if $seen{$partid};
2904: $seen{$partid}++;
1.375 albertel 2905: my $handgrade=$$handgrade{$part_resp};
1.42 ng 2906: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2907: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2908:
1.44 ng 2909: $result.='<input type="hidden" name="partid_'.
2910: $ctsparts.'" value="'.$partid.'" />'."\n";
2911: $result.='<input type="hidden" name="weight_'.
2912: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.324 albertel 2913: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 2914: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 2915: $result.='<table border="0"><tr>';
1.41 ng 2916: my $ctr = 0;
1.42 ng 2917: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 2918: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 2919: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 2920: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 2921: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
2922: $ctr++;
2923: }
2924: $result.='</tr></table>';
1.44 ng 2925: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 2926: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
2927: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 2928: $weight{$partid}.' (problem weight)</td>'."\n";
2929: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 2930: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 2931: $weight{$partid}.')"> '.
1.42 ng 2932: '<option selected="on"> </option>'.
1.125 ng 2933: '<option>excused</option>'.
1.265 www 2934: '<option>reset status</option></select></td>'.
1.266 albertel 2935: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 2936: $ctsparts++;
1.41 ng 2937: }
1.52 albertel 2938: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
2939: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 2940: $result.='<input type="button" value="Reset" '.
1.111 ng 2941: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 2942:
1.44 ng 2943: #table listing all the students in a section/class
2944: #header of table
1.126 ng 2945: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 2946: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 2947: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 2948: '<td>'.&nameUserString('header')."</td>\n";
1.324 albertel 2949: my (@parts) = sort(&getpartlist($symb));
2950: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 2951: my @partids = ();
1.41 ng 2952: foreach my $part (@parts) {
2953: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 2954: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 2955: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 2956: my ($partid) = &split_part_type($part);
1.269 raeburn 2957: push(@partids, $partid);
1.324 albertel 2958: my $display_part=&get_display_part($partid,$symb);
1.41 ng 2959: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 2960: $result.='<td><b>Score Part:</b> '.$display_part.
2961: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 2962: next;
1.207 albertel 2963: } else {
2964: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 2965: }
1.53 albertel 2966: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 2967: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 2968: }
2969: $result.='</tr>';
1.44 ng 2970:
1.270 albertel 2971: my %last_resets =
2972: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 2973:
1.41 ng 2974: #get info for each student
1.44 ng 2975: #list all the students - with points and grade status
1.257 albertel 2976: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 2977: my $ctr = 0;
1.294 albertel 2978: foreach (sort
2979: {
2980: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2981: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2982: }
2983: return $a cmp $b;
2984: } (keys(%$fullname))) {
1.126 ng 2985: $ctr++;
1.324 albertel 2986: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 2987: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 2988: }
2989: $result.='</table></td></tr></table>';
2990: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 2991: $result.='<input type="button" value="Save" '.
1.45 ng 2992: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 2993: if (scalar(%$fullname) eq 0) {
2994: my $colspan=3+scalar(@parts);
1.257 albertel 2995: $result='<font color="red">There are no students in section "'.$env{'form.section'}.
2996: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 2997: }
1.324 albertel 2998: $result.=&show_grading_menu_form($symb);
1.41 ng 2999: return $result;
3000: }
3001:
1.44 ng 3002: #--- call by previous routine to display each student
1.41 ng 3003: sub viewstudentgrade {
1.324 albertel 3004: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3005: my ($uname,$udom) = split(/:/,$student);
3006: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3007: my %aggregates = ();
1.233 albertel 3008: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
3009: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3010: "\n".$ctr.' </td><td> '.
1.44 ng 3011: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 3012: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.257 albertel 3013: '<font color="#999999">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.281 albertel 3014: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3015: foreach my $apart (@$parts) {
3016: my ($part,$type) = &split_part_type($apart);
1.41 ng 3017: my $score=$record{"resource.$part.$type"};
1.276 albertel 3018: $result.='<td align="center">';
1.269 raeburn 3019: my ($aggtries,$totaltries);
3020: unless (exists($aggregates{$part})) {
1.270 albertel 3021: $totaltries = $record{'resource.'.$part.'.tries'};
3022:
3023: $aggtries = $totaltries;
1.269 raeburn 3024: if ($$last_resets{$part}) {
1.270 albertel 3025: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3026: $part);
3027: }
1.269 raeburn 3028: $result.='<input type="hidden" name="'.
3029: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3030: $result.='<input type="hidden" name="'.
3031: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3032: $aggregates{$part} = 1;
3033: }
1.41 ng 3034: if ($type eq 'awarded') {
1.320 albertel 3035: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3036: $result.='<input type="hidden" name="'.
1.89 albertel 3037: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3038: $result.='<input type="text" name="'.
1.89 albertel 3039: 'GD_'.$student.'_'.$part.'_awarded" '.
3040: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3041: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3042: } elsif ($type eq 'solved') {
3043: my ($status,$foo)=split(/_/,$score,2);
3044: $status = 'nothing' if ($status eq '');
1.89 albertel 3045: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3046: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3047: $result.=' <select name="'.
1.89 albertel 3048: 'GD_'.$student.'_'.$part.'_solved" '.
3049: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 3050: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
3051: : '<option selected="on"> </option><option>excused</option>')."\n";
3052: $result.='<option>reset status</option>';
1.126 ng 3053: $result.="</select> </td>\n";
1.122 ng 3054: } else {
3055: $result.='<input type="hidden" name="'.
3056: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3057: "\n";
1.233 albertel 3058: $result.='<input type="text" name="'.
1.122 ng 3059: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3060: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3061: }
3062: }
3063: $result.='</tr>';
3064: return $result;
1.38 ng 3065: }
3066:
1.44 ng 3067: #--- change scores for all the students in a section/class
3068: # record does not get update if unchanged
1.38 ng 3069: sub editgrades {
1.41 ng 3070: my ($request) = @_;
3071:
1.324 albertel 3072: my $symb=&get_symb($request);
1.45 ng 3073: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.257 albertel 3074: $title.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font><br />'."\n";
3075: $title.='<font size=+1><b>Section: </b>'.$env{'form.section'}.'</font>'."\n";
1.126 ng 3076:
1.44 ng 3077: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 3078: $result.= '<table border="0"><tr bgcolor="#deffff">'.
3079: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
3080: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 3081:
3082: my %scoreptr = (
3083: 'correct' =>'correct_by_override',
3084: 'incorrect'=>'incorrect_by_override',
3085: 'excused' =>'excused',
3086: 'ungraded' =>'ungraded_attempted',
3087: 'nothing' => '',
3088: );
1.257 albertel 3089: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3090:
1.44 ng 3091: my (@partid);
3092: my %weight = ();
1.54 albertel 3093: my %columns = ();
1.44 ng 3094: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3095:
1.324 albertel 3096: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3097: my $header;
1.257 albertel 3098: while ($ctr < $env{'form.totalparts'}) {
3099: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 3100: push @partid,$partid;
1.257 albertel 3101: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3102: $ctr++;
1.54 albertel 3103: }
1.324 albertel 3104: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3105: foreach my $partid (@partid) {
3106: $header .= '<td align="center"> <b>Old Score</b> </td>'.
3107: '<td align="center"> <b>New Score</b> </td>';
3108: $columns{$partid}=2;
3109: foreach my $stores (@parts) {
3110: my ($part,$type) = &split_part_type($stores);
3111: if ($part !~ m/^\Q$partid\E/) { next;}
3112: if ($type eq 'awarded' || $type eq 'solved') { next; }
3113: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3114: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 3115: $display =~ s/Number of Attempts/Tries/;
3116: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
3117: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 3118: $columns{$partid}+=2;
3119: }
3120: }
3121: foreach my $partid (@partid) {
1.324 albertel 3122: my $display_part=&get_display_part($partid,$symb);
1.54 albertel 3123: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 3124: '" align="center"><b>Part:</b> '.$display_part.
3125: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 3126:
1.44 ng 3127: }
3128: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 3129: $result .= $header;
1.44 ng 3130: $result .= '</tr>'."\n";
1.93 albertel 3131: my $noupdate;
1.126 ng 3132: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3133: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3134: my $line;
1.257 albertel 3135: my $user = $env{'form.ctr'.$i};
1.281 albertel 3136: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3137: my %newrecord;
3138: my $updateflag = 0;
1.281 albertel 3139: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3140: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3141: if (!&canmodify($usec)) {
1.126 ng 3142: my $numcols=scalar(@partid)*4+2;
1.105 albertel 3143: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
3144: next;
3145: }
1.269 raeburn 3146: my %aggregate = ();
3147: my $aggregateflag = 0;
1.281 albertel 3148: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3149: foreach (@partid) {
1.257 albertel 3150: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3151: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3152: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3153: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3154: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3155: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3156: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3157: my $score;
3158: if ($partial eq '') {
1.257 albertel 3159: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3160: } elsif ($partial > 0) {
3161: $score = 'correct_by_override';
3162: } elsif ($partial == 0) {
3163: $score = 'incorrect_by_override';
3164: }
1.257 albertel 3165: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3166: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3167:
1.292 albertel 3168: $newrecord{'resource.'.$_.'.regrader'}=
3169: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3170: if ($dropMenu eq 'reset status' &&
3171: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3172: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3173: $newrecord{'resource.'.$_.'.solved'} = '';
3174: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3175: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3176: $updateflag = 1;
1.269 raeburn 3177: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3178: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3179: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3180: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3181: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3182: $aggregateflag = 1;
3183: }
1.139 albertel 3184: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3185: $updateflag = 1;
3186: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3187: $newrecord{'resource.'.$_.'.solved'} = $score;
3188: $rec_update++;
1.125 ng 3189: }
3190:
1.93 albertel 3191: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3192: '<td align="center">'.$awarded.
3193: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3194:
1.54 albertel 3195:
3196: my $partid=$_;
3197: foreach my $stores (@parts) {
3198: my ($part,$type) = &split_part_type($stores);
3199: if ($part !~ m/^\Q$partid\E/) { next;}
3200: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3201: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3202: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3203: if ($awarded ne '' && $awarded ne $old_aw) {
3204: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3205: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3206: $updateflag=1;
3207: }
1.93 albertel 3208: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3209: '<td align="center">'.$awarded.' </td>';
3210: }
1.44 ng 3211: }
1.93 albertel 3212: $line.='</tr>'."\n";
1.301 albertel 3213:
3214: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3215: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3216:
1.44 ng 3217: if ($updateflag) {
3218: $count++;
1.257 albertel 3219: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3220: $udom,$uname);
1.301 albertel 3221:
3222: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3223: $cnum,$udom,$uname)) {
3224: # need to figure out if should be in queue.
3225: my %record =
3226: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3227: $udom,$uname);
3228: my $all_graded = 1;
3229: my $none_graded = 1;
3230: foreach my $part (@parts) {
3231: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3232: $all_graded = 0;
3233: } else {
3234: $none_graded = 0;
3235: }
3236: }
3237:
3238: if ($all_graded || $none_graded) {
3239: &Apache::bridgetask::remove_from_queue('gradingqueue',
3240: $symb,$cdom,$cnum,
3241: $udom,$uname);
3242: }
3243: }
3244:
1.126 ng 3245: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3246: $updateCtr++;
1.93 albertel 3247: } else {
1.126 ng 3248: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3249: $noupdateCtr++;
1.44 ng 3250: }
1.269 raeburn 3251: if ($aggregateflag) {
3252: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3253: $cdom,$cnum);
1.269 raeburn 3254: }
1.93 albertel 3255: }
3256: if ($noupdate) {
1.126 ng 3257: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3258: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3259: $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 3260: }
1.72 ng 3261: $result .= '</table></td></tr></table>'."\n".
1.324 albertel 3262: &show_grading_menu_form ($symb);
1.125 ng 3263: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3264: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3265: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3266: return $title.$msg.$result;
1.5 albertel 3267: }
1.54 albertel 3268:
3269: sub split_part_type {
3270: my ($partstr) = @_;
3271: my ($temp,@allparts)=split(/_/,$partstr);
3272: my $type=pop(@allparts);
3273: my $part=join('.',@allparts);
3274: return ($part,$type);
3275: }
3276:
1.44 ng 3277: #------------- end of section for handling grading by section/class ---------
3278: #
3279: #----------------------------------------------------------------------------
3280:
1.5 albertel 3281:
1.44 ng 3282: #----------------------------------------------------------------------------
3283: #
3284: #-------------------------- Next few routines handles grading by csv upload
3285: #
3286: #--- Javascript to handle csv upload
1.27 albertel 3287: sub csvupload_javascript_reverse_associate {
1.246 albertel 3288: my $error1=&mt('You need to specify the username or ID');
3289: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3290: return(<<ENDPICK);
3291: function verify(vf) {
3292: var foundsomething=0;
3293: var founduname=0;
1.243 albertel 3294: var foundID=0;
1.27 albertel 3295: for (i=0;i<=vf.nfields.value;i++) {
3296: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3297: if (i==0 && tw!=0) { foundID=1; }
3298: if (i==1 && tw!=0) { founduname=1; }
3299: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3300: }
1.246 albertel 3301: if (founduname==0 && foundID==0) {
3302: alert('$error1');
3303: return;
1.27 albertel 3304: }
3305: if (foundsomething==0) {
1.246 albertel 3306: alert('$error2');
3307: return;
1.27 albertel 3308: }
3309: vf.submit();
3310: }
3311: function flip(vf,tf) {
3312: var nw=eval('vf.f'+tf+'.selectedIndex');
3313: var i;
3314: for (i=0;i<=vf.nfields.value;i++) {
3315: //can not pick the same destination field for both name and domain
3316: if (((i ==0)||(i ==1)) &&
3317: ((tf==0)||(tf==1)) &&
3318: (i!=tf) &&
3319: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3320: eval('vf.f'+i+'.selectedIndex=0;')
3321: }
3322: }
3323: }
3324: ENDPICK
3325: }
3326:
3327: sub csvupload_javascript_forward_associate {
1.246 albertel 3328: my $error1=&mt('You need to specify the username or ID');
3329: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3330: return(<<ENDPICK);
3331: function verify(vf) {
3332: var foundsomething=0;
3333: var founduname=0;
1.243 albertel 3334: var foundID=0;
1.27 albertel 3335: for (i=0;i<=vf.nfields.value;i++) {
3336: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3337: if (tw==1) { foundID=1; }
3338: if (tw==2) { founduname=1; }
3339: if (tw>3) { foundsomething=1; }
1.27 albertel 3340: }
1.246 albertel 3341: if (founduname==0 && foundID==0) {
3342: alert('$error1');
3343: return;
1.27 albertel 3344: }
3345: if (foundsomething==0) {
1.246 albertel 3346: alert('$error2');
3347: return;
1.27 albertel 3348: }
3349: vf.submit();
3350: }
3351: function flip(vf,tf) {
3352: var nw=eval('vf.f'+tf+'.selectedIndex');
3353: var i;
3354: //can not pick the same destination field twice
3355: for (i=0;i<=vf.nfields.value;i++) {
3356: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3357: eval('vf.f'+i+'.selectedIndex=0;')
3358: }
3359: }
3360: }
3361: ENDPICK
3362: }
3363:
1.26 albertel 3364: sub csvuploadmap_header {
1.324 albertel 3365: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3366: my $javascript;
1.257 albertel 3367: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3368: $javascript=&csvupload_javascript_reverse_associate();
3369: } else {
3370: $javascript=&csvupload_javascript_forward_associate();
3371: }
1.45 ng 3372:
1.324 albertel 3373: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3374: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3375: my $ignore=&mt('Ignore First Line');
1.41 ng 3376: $request->print(<<ENDPICK);
1.26 albertel 3377: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 3378: <h3><font color="#339933">Uploading Class Grades</font></h3>
3379: $result
1.326 albertel 3380: <hr />
1.26 albertel 3381: <h3>Identify fields</h3>
3382: Total number of records found in file: $distotal <hr />
3383: Enter as many fields as you can. The system will inform you and bring you back
3384: to this page if the data selected is insufficient to run your class.<hr />
3385: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3386: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3387: <input type="hidden" name="associate" value="" />
3388: <input type="hidden" name="phase" value="three" />
3389: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3390: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3391: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3392: <input type="hidden" name="upfile_associate"
1.257 albertel 3393: value="$env{'form.upfile_associate'}" />
1.26 albertel 3394: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3395: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3396: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3397: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3398: <hr />
3399: <script type="text/javascript" language="Javascript">
3400: $javascript
3401: </script>
3402: ENDPICK
1.118 ng 3403: return '';
1.26 albertel 3404:
3405: }
3406:
3407: sub csvupload_fields {
1.324 albertel 3408: my ($symb) = @_;
3409: my (@parts) = &getpartlist($symb);
1.243 albertel 3410: my @fields=(['ID','Student ID'],
3411: ['username','Student Username'],
3412: ['domain','Student Domain']);
1.324 albertel 3413: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3414: foreach my $part (sort(@parts)) {
3415: my @datum;
3416: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3417: my $name=$part;
3418: if (!$display) { $display = $name; }
3419: @datum=($name,$display);
1.244 albertel 3420: if ($name=~/^stores_(.*)_awarded/) {
3421: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3422: }
1.41 ng 3423: push(@fields,\@datum);
3424: }
3425: return (@fields);
1.26 albertel 3426: }
3427:
3428: sub csvuploadmap_footer {
1.41 ng 3429: my ($request,$i,$keyfields) =@_;
3430: $request->print(<<ENDPICK);
1.26 albertel 3431: </table>
3432: <input type="hidden" name="nfields" value="$i" />
3433: <input type="hidden" name="keyfields" value="$keyfields" />
3434: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3435: </form>
3436: ENDPICK
3437: }
3438:
1.283 albertel 3439: sub checkforfile_js {
1.86 ng 3440: my $result =<<CSVFORMJS;
3441: <script type="text/javascript" language="javascript">
3442: function checkUpload(formname) {
3443: if (formname.upfile.value == "") {
3444: alert("Please use the browse button to select a file from your local directory.");
3445: return false;
3446: }
3447: formname.submit();
3448: }
3449: </script>
3450: CSVFORMJS
1.283 albertel 3451: return $result;
3452: }
3453:
3454: sub upcsvScores_form {
3455: my ($request) = shift;
1.324 albertel 3456: my ($symb)=&get_symb($request);
1.283 albertel 3457: if (!$symb) {return '';}
3458: my $result=&checkforfile_js();
1.257 albertel 3459: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3460: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3461: $result.=$table;
1.326 albertel 3462: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3463: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.370 www 3464: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource').
1.86 ng 3465: '.</b></td></tr>'."\n";
3466: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3467: my $upload=&mt("Upload Scores");
1.86 ng 3468: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3469: my $ignore=&mt('Ignore First Line');
1.86 ng 3470: $result.=<<ENDUPFORM;
1.106 albertel 3471: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3472: <input type="hidden" name="symb" value="$symb" />
3473: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3474: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3475: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3476: $upfile_select
1.370 www 3477: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3478: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3479: </form>
3480: ENDUPFORM
1.370 www 3481: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3482: &mt("How do I create a CSV file from a spreadsheet"))
3483: .'</td></tr></table>'."\n";
1.86 ng 3484: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3485: $result.=&show_grading_menu_form($symb);
1.86 ng 3486: return $result;
3487: }
3488:
3489:
1.26 albertel 3490: sub csvuploadmap {
1.41 ng 3491: my ($request)= @_;
1.324 albertel 3492: my ($symb)=&get_symb($request);
1.41 ng 3493: if (!$symb) {return '';}
1.72 ng 3494:
1.41 ng 3495: my $datatoken;
1.257 albertel 3496: if (!$env{'form.datatoken'}) {
1.41 ng 3497: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3498: } else {
1.257 albertel 3499: $datatoken=$env{'form.datatoken'};
1.41 ng 3500: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3501: }
1.41 ng 3502: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3503: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3504: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3505: my ($i,$keyfields);
3506: if (@records) {
1.324 albertel 3507: my @fields=&csvupload_fields($symb);
1.45 ng 3508:
1.257 albertel 3509: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3510: &Apache::loncommon::csv_print_samples($request,\@records);
3511: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3512: \@fields);
3513: foreach (@fields) { $keyfields.=$_->[0].','; }
3514: chop($keyfields);
3515: } else {
3516: unshift(@fields,['none','']);
3517: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3518: \@fields);
1.311 banghart 3519: foreach my $rec (@records) {
3520: my %temp = &Apache::loncommon::record_sep($rec);
3521: if (%temp) {
3522: $keyfields=join(',',sort(keys(%temp)));
3523: last;
3524: }
3525: }
1.41 ng 3526: }
3527: }
3528: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3529: $request->print(&show_grading_menu_form($symb));
1.72 ng 3530:
1.41 ng 3531: return '';
1.27 albertel 3532: }
3533:
1.246 albertel 3534: sub csvuploadoptions {
1.41 ng 3535: my ($request)= @_;
1.324 albertel 3536: my ($symb)=&get_symb($request);
1.257 albertel 3537: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3538: my $ignore=&mt('Ignore First Line');
3539: $request->print(<<ENDPICK);
3540: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
3541: <h3><font color="#339933">Uploading Class Grade Options</font></h3>
3542: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3543: <!--
1.246 albertel 3544: <p>
3545: <label>
3546: <input type="checkbox" name="show_full_results" />
3547: Show a table of all changes
3548: </label>
3549: </p>
1.302 albertel 3550: -->
1.246 albertel 3551: <p>
3552: <label>
3553: <input type="checkbox" name="overwite_scores" checked="checked" />
3554: Overwrite any existing score
3555: </label>
3556: </p>
3557: ENDPICK
3558: my %fields=&get_fields();
3559: if (!defined($fields{'domain'})) {
1.257 albertel 3560: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3561: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3562: }
1.257 albertel 3563: foreach my $key (sort(keys(%env))) {
1.246 albertel 3564: if ($key !~ /^form\.(.*)$/) { next; }
3565: my $cleankey=$1;
3566: if ($cleankey eq 'command') { next; }
3567: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3568: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3569: }
3570: # FIXME do a check for any duplicated user ids...
3571: # FIXME do a check for any invalid user ids?...
1.290 albertel 3572: $request->print('<input type="submit" value="Assign Grades" /><br />
3573: <hr /></form>'."\n");
1.324 albertel 3574: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3575: return '';
3576: }
3577:
3578: sub get_fields {
3579: my %fields;
1.257 albertel 3580: my @keyfields = split(/\,/,$env{'form.keyfields'});
3581: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3582: if ($env{'form.upfile_associate'} eq 'reverse') {
3583: if ($env{'form.f'.$i} ne 'none') {
3584: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3585: }
3586: } else {
1.257 albertel 3587: if ($env{'form.f'.$i} ne 'none') {
3588: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3589: }
3590: }
1.27 albertel 3591: }
1.246 albertel 3592: return %fields;
3593: }
3594:
3595: sub csvuploadassign {
3596: my ($request)= @_;
1.324 albertel 3597: my ($symb)=&get_symb($request);
1.246 albertel 3598: if (!$symb) {return '';}
1.345 bowersj2 3599: my $error_msg = '';
1.246 albertel 3600: &Apache::loncommon::load_tmp_file($request);
3601: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3602: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3603: my %fields=&get_fields();
1.41 ng 3604: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3605: my $courseid=$env{'request.course.id'};
1.97 albertel 3606: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3607: my @notallowed;
1.41 ng 3608: my @skipped;
3609: my $countdone=0;
3610: foreach my $grade (@gradedata) {
3611: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3612: my $domain;
3613: if ($entries{$fields{'domain'}}) {
3614: $domain=$entries{$fields{'domain'}};
3615: } else {
1.257 albertel 3616: $domain=$env{'form.default_domain'};
1.246 albertel 3617: }
1.243 albertel 3618: $domain=~s/\s//g;
1.41 ng 3619: my $username=$entries{$fields{'username'}};
1.160 albertel 3620: $username=~s/\s//g;
1.243 albertel 3621: if (!$username) {
3622: my $id=$entries{$fields{'ID'}};
1.247 albertel 3623: $id=~s/\s//g;
1.243 albertel 3624: my %ids=&Apache::lonnet::idget($domain,$id);
3625: $username=$ids{$id};
3626: }
1.41 ng 3627: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3628: my $id=$entries{$fields{'ID'}};
3629: $id=~s/\s//g;
3630: if ($id) {
3631: push(@skipped,"$id:$domain");
3632: } else {
3633: push(@skipped,"$username:$domain");
3634: }
1.41 ng 3635: next;
3636: }
1.108 albertel 3637: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3638: if (!&canmodify($usec)) {
3639: push(@notallowed,"$username:$domain");
3640: next;
3641: }
1.244 albertel 3642: my %points;
1.41 ng 3643: my %grades;
3644: foreach my $dest (keys(%fields)) {
1.244 albertel 3645: if ($dest eq 'ID' || $dest eq 'username' ||
3646: $dest eq 'domain') { next; }
3647: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3648: if ($dest=~/stores_(.*)_points/) {
3649: my $part=$1;
3650: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3651: $symb,$domain,$username);
1.345 bowersj2 3652: if ($wgt) {
3653: $entries{$fields{$dest}}=~s/\s//g;
3654: my $pcr=$entries{$fields{$dest}} / $wgt;
3655: my $award='correct_by_override';
3656: $grades{"resource.$part.awarded"}=$pcr;
3657: $grades{"resource.$part.solved"}=$award;
3658: $points{$part}=1;
3659: } else {
3660: $error_msg = "<br />" .
3661: &mt("Some point values were assigned"
3662: ." for problems with a weight "
3663: ."of zero. These values were "
3664: ."ignored.");
3665: }
1.244 albertel 3666: } else {
3667: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3668: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3669: my $store_key=$dest;
3670: $store_key=~s/^stores/resource/;
3671: $store_key=~s/_/\./g;
3672: $grades{$store_key}=$entries{$fields{$dest}};
3673: }
1.41 ng 3674: }
1.244 albertel 3675: if (! %grades) { push(@skipped,"$username:$domain no data to store"); }
1.257 albertel 3676: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3677: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3678: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3679: $env{'request.course.id'},
3680: $domain,$username);
3681: if ($result eq 'ok') {
3682: $request->print('.');
3683: } else {
3684: $request->print("<p>
3685: <font color='red'>
3686: Failed to store student $username\@$domain.
3687: Message when trying to store was ($result)
3688: </font>
3689: </p>" );
3690: }
1.41 ng 3691: $request->rflush();
3692: $countdone++;
3693: }
3694: $request->print("<br />Stored $countdone students\n");
3695: if (@skipped) {
1.325 www 3696: $request->print('<p><font size="+1"><b>Skipped Students</b></font></p>');
1.106 albertel 3697: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3698: }
3699: if (@notallowed) {
3700: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
3701: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3702: }
1.106 albertel 3703: $request->print("<br />\n");
1.324 albertel 3704: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 3705: return $error_msg;
1.26 albertel 3706: }
1.44 ng 3707: #------------- end of section for handling csv file upload ---------
3708: #
3709: #-------------------------------------------------------------------
3710: #
1.122 ng 3711: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3712: #
3713: #--- Select a page/sequence and a student to grade
1.68 ng 3714: sub pickStudentPage {
3715: my ($request) = shift;
3716:
3717: $request->print(<<LISTJAVASCRIPT);
3718: <script type="text/javascript" language="javascript">
3719:
3720: function checkPickOne(formname) {
1.76 ng 3721: if (radioSelection(formname.student) == null) {
1.68 ng 3722: alert("Please select the student you wish to grade.");
3723: return;
3724: }
1.125 ng 3725: ptr = pullDownSelection(formname.selectpage);
3726: formname.page.value = formname["page"+ptr].value;
3727: formname.title.value = formname["title"+ptr].value;
1.68 ng 3728: formname.submit();
3729: }
3730:
3731: </script>
3732: LISTJAVASCRIPT
1.118 ng 3733: &commonJSfunctions($request);
1.324 albertel 3734: my ($symb) = &get_symb($request);
1.257 albertel 3735: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3736: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3737: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3738:
3739: my $result='<h3><font color="#339933"> '.
3740: 'Manual Grading by Page or Sequence</font></h3>';
3741:
1.80 ng 3742: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3743: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3744: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3745: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3746: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3747: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3748: my $ctr=0;
1.68 ng 3749: foreach (@$titles) {
3750: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3751: $result.='<option value="'.$ctr.'" '.
1.71 ng 3752: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3753: '>'.$showtitle.'</option>'."\n";
1.70 ng 3754: $ctr++;
1.68 ng 3755: }
1.326 albertel 3756: $result.= '</select>'."<br />\n";
1.70 ng 3757: $ctr=0;
3758: foreach (@$titles) {
3759: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3760: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3761: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3762: $ctr++;
3763: }
1.72 ng 3764: $result.='<input type="hidden" name="page" />'."\n".
3765: '<input type="hidden" name="title" />'."\n";
1.68 ng 3766:
1.288 albertel 3767: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3768: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3769:
1.71 ng 3770: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3771: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3772: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3773: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3774:
1.68 ng 3775: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3776: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3777: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.80 ng 3778: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 3779: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3780:
1.80 ng 3781: $result.=' <input type="button" '.
1.126 ng 3782: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3783:
1.68 ng 3784: $request->print($result);
3785:
1.326 albertel 3786: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br />'.
1.68 ng 3787: '<table border="0"><tr><td bgcolor="#777777">'.
3788: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3789: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3790: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3791: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3792: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3793:
1.76 ng 3794: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3795: my $ptr = 1;
1.294 albertel 3796: foreach my $student (sort
3797: {
3798: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3799: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3800: }
3801: return $a cmp $b;
3802: } (keys(%$fullname))) {
1.68 ng 3803: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3804: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3805: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3806: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3807: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3808: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3809: $ptr++;
3810: }
1.381 ! albertel 3811: $studentTable.='</td><td> </td><td> </td></tr>' if ($ptr%2 == 0);
! 3812: $studentTable.='</table></td></tr></table>'."\n";
1.126 ng 3813: $studentTable.='<input type="button" '.
3814: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3815:
1.324 albertel 3816: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 3817: $request->print($studentTable);
3818:
3819: return '';
3820: }
3821:
3822: sub getSymbMap {
1.74 albertel 3823: my ($request) = @_;
1.132 bowersj2 3824: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3825:
3826: my %symbx = ();
3827: my @titles = ();
1.117 bowersj2 3828: my $minder = 0;
3829:
3830: # Gather every sequence that has problems.
1.240 albertel 3831: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3832: 1,0,1);
1.117 bowersj2 3833: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3834: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 ! albertel 3835: my $title = $minder.'.'.
! 3836: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
! 3837: push(@titles, $title); # minder in case two titles are identical
! 3838: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 3839: $minder++;
1.241 albertel 3840: }
1.68 ng 3841: }
3842: return \@titles,\%symbx;
3843: }
3844:
1.72 ng 3845: #
3846: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3847: sub displayPage {
3848: my ($request) = shift;
3849:
1.324 albertel 3850: my ($symb) = &get_symb($request);
1.257 albertel 3851: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3852: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3853: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3854: my $pageTitle = $env{'form.page'};
1.103 albertel 3855: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3856: my ($uname,$udom) = split(/:/,$env{'form.student'});
3857: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3858:
3859: #need to make sure we have the correct data for later EXT calls,
3860: #thus invalidate the cache
3861: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3862: $env{'course.'.$env{'request.course.id'}.'.num'},
3863: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3864: &Apache::lonnet::clear_EXT_cache_status();
3865:
1.103 albertel 3866: if (!&canview($usec)) {
1.257 albertel 3867: $request->print('<font color="red">Unable to view requested student.('.$env{'form.student'}.')</font>');
1.324 albertel 3868: $request->print(&show_grading_menu_form($symb));
1.103 albertel 3869: return;
3870: }
1.257 albertel 3871: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3872: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3873: '</h3>'."\n";
1.71 ng 3874: &sub_page_js($request);
3875: $request->print($result);
3876:
1.132 bowersj2 3877: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3878: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3879: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3880: if (!$map) {
3881: $request->print('<font color="red">Unable to view requested sequence. ('.$resUrl.')</font>');
1.324 albertel 3882: $request->print(&show_grading_menu_form($symb));
1.288 albertel 3883: return;
3884: }
1.68 ng 3885: my $iterator = $navmap->getIterator($map->map_start(),
3886: $map->map_finish());
3887:
1.71 ng 3888: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3889: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3890: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3891: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3892: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3893: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.72 ng 3894: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3895: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3896: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3897:
1.381 ! albertel 3898: my $checkIcon = '<img alt="'.&mt('Check Mark').
! 3899: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 3900: '/check.gif" height="16" border="0" />';
3901:
1.118 ng 3902: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
3903: ' symbol.'."\n".
1.71 ng 3904: '<table border="0"><tr><td bgcolor="#777777">'.
3905: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 3906: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 3907: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 3908:
1.329 albertel 3909: &Apache::lonxml::clear_problem_counter();
1.196 albertel 3910: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 3911: $iterator->next(); # skip the first BEGIN_MAP
3912: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3913: while ($depth > 0) {
1.68 ng 3914: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3915: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 3916:
1.235 albertel 3917: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3918: my $parts = $curRes->parts();
1.68 ng 3919: my $title = $curRes->compTitle();
1.71 ng 3920: my $symbx = $curRes->symb();
1.196 albertel 3921: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 3922: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 3923: $studentTable.='<td valign="top">';
1.257 albertel 3924: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 3925: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
3926: undef,'both');
1.71 ng 3927: } else {
1.257 albertel 3928: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'});
1.80 ng 3929: $companswer =~ s|<form(.*?)>||g;
3930: $companswer =~ s|</form>||g;
1.71 ng 3931: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 3932: # $companswer =~ s/$1/ /ms;
1.326 albertel 3933: # $request->print('match='.$1."<br />\n");
1.71 ng 3934: # }
1.116 ng 3935: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.326 albertel 3936: $studentTable.=' <b>'.$title.'</b> <br /> <b>Correct answer:</b><br />'.$companswer;
1.71 ng 3937: }
3938:
1.257 albertel 3939: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 3940:
1.257 albertel 3941: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 3942: if ($record{'version'} eq '') {
3943: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
3944: } else {
1.116 ng 3945: my %responseType = ();
3946: foreach my $partid (@{$parts}) {
1.147 albertel 3947: my @responseIds =$curRes->responseIds($partid);
3948: my @responseType =$curRes->responseType($partid);
3949: my %responseIds;
3950: for (my $i=0;$i<=$#responseIds;$i++) {
3951: $responseIds{$responseIds[$i]}=$responseType[$i];
3952: }
3953: $responseType{$partid} = \%responseIds;
1.116 ng 3954: }
1.148 albertel 3955: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 3956:
1.71 ng 3957: }
1.257 albertel 3958: } elsif ($env{'form.lastSub'} eq 'all') {
3959: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 3960: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 3961: $env{'request.course.id'},
1.71 ng 3962: '','.submission');
3963:
3964: }
1.103 albertel 3965: if (&canmodify($usec)) {
3966: foreach my $partid (@{$parts}) {
3967: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
3968: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
3969: $question++;
3970: }
1.196 albertel 3971: $prob++;
1.71 ng 3972: }
3973: $studentTable.='</td></tr>';
1.68 ng 3974:
1.103 albertel 3975: }
1.68 ng 3976: $curRes = $iterator->next();
3977: }
3978:
1.381 ! albertel 3979: $studentTable.='</table></td></tr></table>'."\n".
1.125 ng 3980: '<input type="button" value="Save" '.
1.381 ! albertel 3981: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 3982: '</form>'."\n";
1.324 albertel 3983: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 3984: $request->print($studentTable);
3985:
3986: return '';
1.119 ng 3987: }
3988:
3989: sub displaySubByDates {
1.148 albertel 3990: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 3991: my $isCODE=0;
1.335 albertel 3992: my $isTask = ($symb =~/\.task$/);
1.224 albertel 3993: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 3994: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
3995: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
3996: '<td><b>Date/Time</b></td>'.
1.224 albertel 3997: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 3998: '<td><b>Submission</b></td>'.
3999: '<td><b>Status </b></td></tr>';
4000: my ($version);
4001: my %mark;
1.148 albertel 4002: my %orders;
1.119 ng 4003: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4004: if (!exists($$record{'1:timestamp'})) {
4005: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
4006: }
1.335 albertel 4007:
4008: my $interaction;
1.119 ng 4009: for ($version=1;$version<=$$record{'version'};$version++) {
4010: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
1.335 albertel 4011: if (exists($$record{$version.':resource.0.version'})) {
4012: $interaction = $$record{$version.':resource.0.version'};
4013: }
4014:
4015: my $where = ($isTask ? "$version:resource.$interaction"
4016: : "$version:resource");
4017: #&Apache::lonnet::logthis(" got $where");
1.119 ng 4018: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 4019: if ($isCODE) {
4020: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4021: }
1.119 ng 4022: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4023: my @displaySub = ();
4024: foreach my $partid (@{$parts}) {
1.335 albertel 4025: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4026: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4027:
4028:
1.122 ng 4029: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4030: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4031: foreach my $matchKey (@matchKey) {
1.198 albertel 4032: if (exists($$record{$version.':'.$matchKey}) &&
4033: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4034:
4035: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4036: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
4037: #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey});
1.207 albertel 4038: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.147 albertel 4039: $displaySub[0].='<font color="#999999">(ID '.
1.207 albertel 4040: $responseId.')</font> <b>';
1.335 albertel 4041: if ($$record{"$where.$partid.tries"} eq '') {
1.147 albertel 4042: $displaySub[0].='Trial not counted';
4043: } else {
4044: $displaySub[0].='Trial '.
1.335 albertel 4045: $$record{"$where.$partid.tries"};
1.147 albertel 4046: }
1.335 albertel 4047: my $responseType=($isTask ? 'Task'
4048: : $responseType->{$partid}->{$responseId});
1.148 albertel 4049: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4050: if (!exists($orders{$partid}->{$responseId})) {
4051: $orders{$partid}->{$responseId}=
4052: &get_order($partid,$responseId,$symb,$uname,$udom);
4053: }
1.147 albertel 4054: $displaySub[0].='</b> '.
1.336 albertel 4055: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4056: }
4057: }
1.335 albertel 4058: if (exists($$record{"$where.$partid.checkedin"})) {
4059: $displaySub[1].='Checked in by '.
4060: $$record{"$where.$partid.checkedin"}.' into slot '.
4061: $$record{"$where.$partid.checkedin.slot"}.
4062: '<br />';
4063: }
4064: if (exists $$record{"$where.$partid.award"}) {
1.207 albertel 4065: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.335 albertel 4066: lc($$record{"$where.$partid.award"}).' '.
4067: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4068: '<br />';
4069: }
1.335 albertel 4070: if (exists $$record{"$where.$partid.regrader"}) {
4071: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4072: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4073: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4074: $displaySub[2].=
4075: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4076: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4077: }
4078: }
4079: # needed because old essay regrader has not parts info
4080: if (exists $$record{"$version:resource.regrader"}) {
4081: $displaySub[2].=$$record{"$version:resource.regrader"};
4082: }
4083: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4084: if ($displaySub[2]) {
4085: $studentTable.='Manually graded by '.$displaySub[2];
4086: }
1.381 ! albertel 4087: $studentTable.=' </td></tr>3';
1.147 albertel 4088:
1.119 ng 4089: }
4090: $studentTable.='</table></td></tr></table>';
4091: return $studentTable;
1.71 ng 4092: }
4093:
4094: sub updateGradeByPage {
4095: my ($request) = shift;
4096:
1.257 albertel 4097: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4098: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4099: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4100: my $pageTitle = $env{'form.page'};
1.103 albertel 4101: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4102: my ($uname,$udom) = split(/:/,$env{'form.student'});
4103: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4104: if (!&canmodify($usec)) {
1.257 albertel 4105: $request->print('<font color="red">Unable to modify requested student.('.$env{'form.student'}.'</font>');
1.324 albertel 4106: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4107: return;
4108: }
1.257 albertel 4109: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
4110: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4111: '</h3>'."\n";
1.70 ng 4112:
1.68 ng 4113: $request->print($result);
4114:
1.132 bowersj2 4115: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4116: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4117: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4118: if (!$map) {
4119: $request->print('<font color="red">Unable to grade requested sequence. ('.$resUrl.')</font>');
1.324 albertel 4120: my ($symb)=&get_symb($request);
4121: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4122: return;
4123: }
1.71 ng 4124: my $iterator = $navmap->getIterator($map->map_start(),
4125: $map->map_finish());
1.70 ng 4126:
1.71 ng 4127: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 4128: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 4129: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 4130: '<td><b> Title </b></td>'.
4131: '<td><b> Previous Score </b></td>'.
4132: '<td><b> New Score </b></td></tr>';
4133:
4134: $iterator->next(); # skip the first BEGIN_MAP
4135: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4136: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4137: while ($depth > 0) {
1.71 ng 4138: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4139: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4140:
4141: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 4142: my $parts = $curRes->parts();
1.71 ng 4143: my $title = $curRes->compTitle();
4144: my $symbx = $curRes->symb();
1.196 albertel 4145: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4146: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4147: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4148:
4149: my %newrecord=();
4150: my @displayPts=();
1.269 raeburn 4151: my %aggregate = ();
4152: my $aggregateflag = 0;
1.71 ng 4153: foreach my $partid (@{$parts}) {
1.257 albertel 4154: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4155: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4156:
1.257 albertel 4157: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4158: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4159: my $partial = $newpts/$wgt;
4160: my $score;
4161: if ($partial > 0) {
4162: $score = 'correct_by_override';
1.125 ng 4163: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4164: $score = 'incorrect_by_override';
4165: }
1.257 albertel 4166: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4167: if ($dropMenu eq 'excused') {
1.71 ng 4168: $partial = '';
4169: $score = 'excused';
1.125 ng 4170: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4171: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4172: $newrecord{'resource.'.$partid.'.tries'} = 0;
4173: $newrecord{'resource.'.$partid.'.solved'} = '';
4174: $newrecord{'resource.'.$partid.'.award'} = '';
4175: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4176: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4177: $changeflag++;
4178: $newpts = '';
1.269 raeburn 4179:
4180: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4181: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4182: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4183: if ($aggtries > 0) {
4184: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4185: $aggregateflag = 1;
4186: }
1.71 ng 4187: }
1.324 albertel 4188: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4189: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4190: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4191: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4192: ' <br />';
1.207 albertel 4193: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4194: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4195: ' <br />';
1.71 ng 4196: $question++;
1.380 albertel 4197: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4198:
1.71 ng 4199: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4200: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4201: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4202: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4203:
4204: $changeflag++;
4205: }
4206: if (scalar(keys(%newrecord)) > 0) {
1.257 albertel 4207: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4208: $udom,$uname);
1.380 albertel 4209: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4210: $udom,$uname);
4211: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4212: $cdom,$cnum,$udom,$uname);
1.71 ng 4213: }
1.380 albertel 4214:
1.269 raeburn 4215: if ($aggregateflag) {
4216: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4217: $env{'course.'.$env{'request.course.id'}.'.domain'},
4218: $env{'course.'.$env{'request.course.id'}.'.num'});
4219: }
1.125 ng 4220:
1.71 ng 4221: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4222: '<td valign="top">'.$displayPts[1].'</td>'.
4223: '</tr>';
1.68 ng 4224:
1.196 albertel 4225: $prob++;
1.68 ng 4226: }
1.71 ng 4227: $curRes = $iterator->next();
1.68 ng 4228: }
1.98 albertel 4229:
1.71 ng 4230: $studentTable.='</td></tr></table></td></tr></table>';
1.324 albertel 4231: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.76 ng 4232: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4233: 'The scores were changed for '.
4234: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4235: $request->print($grademsg.$studentTable);
1.68 ng 4236:
1.70 ng 4237: return '';
4238: }
4239:
1.72 ng 4240: #-------- end of section for handling grading by page/sequence ---------
4241: #
4242: #-------------------------------------------------------------------
4243:
1.75 albertel 4244: #--------------------Scantron Grading-----------------------------------
4245: #
4246: #------ start of section for handling grading by page/sequence ---------
4247:
1.81 albertel 4248: sub defaultFormData {
1.324 albertel 4249: my ($symb)=@_;
1.81 albertel 4250: return '
4251: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 4252: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4253: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4254: }
4255:
1.75 albertel 4256: sub getSequenceDropDown {
4257: my ($request,$symb)=@_;
4258: my $result='<select name="selectpage">'."\n";
4259: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4260: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4261: my $ctr=0;
4262: foreach (@$titles) {
4263: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4264: $result.='<option value="'.$$symbx{$_}.'" '.
4265: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4266: '>'.$showtitle.'</option>'."\n";
4267: $ctr++;
4268: }
4269: $result.= '</select>';
4270: return $result;
4271: }
4272:
1.202 albertel 4273: sub scantron_filenames {
1.257 albertel 4274: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4275: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4276: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.359 www 4277: &propath($cdom,$cname));
1.202 albertel 4278: my @possiblenames;
1.201 albertel 4279: foreach my $filename (sort(@files)) {
1.157 albertel 4280: ($filename)=split(/&/,$filename);
4281: if ($filename!~/^scantron_orig_/) { next ; }
4282: $filename=~s/^scantron_orig_//;
1.202 albertel 4283: push(@possiblenames,$filename);
4284: }
4285: return @possiblenames;
4286: }
4287:
4288: sub scantron_uploads {
1.209 ng 4289: my ($file2grade) = @_;
1.202 albertel 4290: my $result= '<select name="scantron_selectfile">';
4291: $result.="<option></option>";
4292: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4293: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4294: }
4295: $result.="</select>";
4296: return $result;
4297: }
4298:
1.82 albertel 4299: sub scantron_scantab {
4300: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4301: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4302: $result.='<option></option>'."\n";
1.82 albertel 4303: foreach my $line (<$fh>) {
4304: my ($name,$descrip)=split(/:/,$line);
4305: if ($name =~ /^\#/) { next; }
4306: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4307: }
4308: $result.='</select>'."\n";
4309:
4310: return $result;
4311: }
4312:
1.186 albertel 4313: sub scantron_CODElist {
1.257 albertel 4314: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4315: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4316: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4317: my $namechoice='<option></option>';
1.225 albertel 4318: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4319: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4320: if ($name =~ /^type\0/) { next; }
1.186 albertel 4321: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4322: }
4323: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4324: return $namechoice;
4325: }
4326:
4327: sub scantron_CODEunique {
1.381 ! albertel 4328: my $result='<span style="white-space: nowrap;">
1.272 albertel 4329: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4330: value="yes" checked="checked" /> Yes </label>
1.381 ! albertel 4331: </span>
! 4332: <span style="white-space: nowrap;">
1.272 albertel 4333: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4334: value="no" /> No </label>
1.381 ! albertel 4335: </span>';
1.186 albertel 4336: return $result;
4337: }
4338:
1.75 albertel 4339: sub scantron_selectphase {
1.209 ng 4340: my ($r,$file2grade) = @_;
1.324 albertel 4341: my ($symb)=&get_symb($r);
1.75 albertel 4342: if (!$symb) {return '';}
4343: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.324 albertel 4344: my $default_form_data=&defaultFormData($symb);
4345: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4346: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4347: my $format_selector=&scantron_scantab();
1.186 albertel 4348: my $CODE_selector=&scantron_CODElist();
4349: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4350: my $result;
1.157 albertel 4351: #FIXME allow instructor to be able to download the scantron file
4352: # and to upload it,
1.75 albertel 4353: $result.= <<SCANTRONFORM;
1.162 albertel 4354: <table width="100%" border="0">
1.75 albertel 4355: <tr>
1.226 albertel 4356: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4357: <td bgcolor="#777777">
1.203 albertel 4358: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4359: $default_form_data
1.75 albertel 4360: <table width="100%" border="0">
4361: <tr bgcolor="#e6ffff">
1.174 albertel 4362: <td colspan="2">
4363: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4364: </td>
4365: </tr>
4366: <tr bgcolor="#ffffe6">
1.174 albertel 4367: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4368: </tr>
4369: <tr bgcolor="#ffffe6">
1.174 albertel 4370: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4371: </tr>
1.82 albertel 4372: <tr bgcolor="#ffffe6">
1.174 albertel 4373: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4374: </tr>
1.157 albertel 4375: <tr bgcolor="#ffffe6">
1.186 albertel 4376: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4377: </tr>
4378: <tr bgcolor="#ffffe6">
4379: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4380: </tr>
4381: <tr bgcolor="#ffffe6">
1.187 albertel 4382: <td> Options: </td>
4383: <td>
1.272 albertel 4384: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
1.331 albertel 4385: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label> <br />
4386: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
1.187 albertel 4387: </td>
4388: </tr>
4389: <tr bgcolor="#ffffe6">
1.174 albertel 4390: <td colspan="2">
1.265 www 4391: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4392: </td>
4393: </tr>
4394: </table>
1.226 albertel 4395: </td>
4396: </form>
1.162 albertel 4397: </tr>
4398: SCANTRONFORM
4399:
4400: $r->print($result);
4401:
1.257 albertel 4402: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4403: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4404:
4405: $r->print(<<SCANTRONFORM);
4406: <tr>
4407: <td bgcolor="#777777">
4408: <table width="100%" border="0">
4409: <tr bgcolor="#e6ffff">
4410: <td>
1.174 albertel 4411: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4412: </td>
4413: </tr>
4414: <tr bgcolor="#ffffe6">
4415: <td>
4416: SCANTRONFORM
1.324 albertel 4417: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 4418: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4419: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4420: $r->print(<<UPLOAD);
4421: <script type="text/javascript" language="javascript">
4422: function checkUpload(formname) {
4423: if (formname.upfile.value == "") {
4424: alert("Please use the browse button to select a file from your local directory.");
4425: return false;
4426: }
4427: formname.submit();
4428: }
4429: </script>
4430:
4431: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4432: $default_form_data
4433: <input name='courseid' type='hidden' value='$cnum' />
4434: <input name='domainid' type='hidden' value='$cdom' />
4435: <input name='command' value='scantronupload_save' type='hidden' />
4436: File to upload:<input type="file" name="upfile" size="50" />
4437: <br />
4438: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4439: </form>
4440: UPLOAD
1.162 albertel 4441:
4442: $r->print(<<SCANTRONFORM);
4443: </td>
4444: </tr>
1.75 albertel 4445: </table>
4446: </td>
4447: </tr>
1.162 albertel 4448: SCANTRONFORM
4449: }
1.187 albertel 4450: $r->print(<<SCANTRONFORM);
4451: <tr>
1.226 albertel 4452: <form action='/adm/grades' name='scantron_download'>
4453: <td bgcolor="#777777">
1.379 albertel 4454: $default_form_data
1.187 albertel 4455: <input type="hidden" name="command" value="scantron_download" />
4456: <table width="100%" border="0">
4457: <tr bgcolor="#e6ffff">
4458: <td colspan="2">
4459: <b>Download a scoring office file</b>
4460: </td>
4461: </tr>
4462: <tr bgcolor="#ffffe6">
4463: <td> Filename of scoring office file: </td><td> $file_selector </td>
4464: </tr>
4465: <tr bgcolor="#ffffe6">
4466: <td colspan="2">
1.293 www 4467: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4468: </td>
4469: </tr>
4470: </table>
1.226 albertel 4471: </td>
4472: </form>
1.187 albertel 4473: </tr>
4474: SCANTRONFORM
1.162 albertel 4475:
4476: $r->print(<<SCANTRONFORM);
1.75 albertel 4477: </table>
1.81 albertel 4478: $grading_menu_button
1.75 albertel 4479: SCANTRONFORM
4480:
1.162 albertel 4481: return
1.75 albertel 4482: }
4483:
1.82 albertel 4484: sub get_scantron_config {
4485: my ($which) = @_;
4486: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4487: my %config;
1.157 albertel 4488: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4489: foreach my $line (<$fh>) {
4490: my ($name,$descrip)=split(/:/,$line);
4491: if ($name ne $which ) { next; }
4492: chomp($line);
4493: my @config=split(/:/,$line);
4494: $config{'name'}=$config[0];
4495: $config{'description'}=$config[1];
4496: $config{'CODElocation'}=$config[2];
4497: $config{'CODEstart'}=$config[3];
4498: $config{'CODElength'}=$config[4];
4499: $config{'IDstart'}=$config[5];
4500: $config{'IDlength'}=$config[6];
4501: $config{'Qstart'}=$config[7];
4502: $config{'Qlength'}=$config[8];
4503: $config{'Qoff'}=$config[9];
4504: $config{'Qon'}=$config[10];
1.157 albertel 4505: $config{'PaperID'}=$config[11];
4506: $config{'PaperIDlength'}=$config[12];
4507: $config{'FirstName'}=$config[13];
4508: $config{'FirstNamelength'}=$config[14];
4509: $config{'LastName'}=$config[15];
4510: $config{'LastNamelength'}=$config[16];
1.82 albertel 4511: last;
4512: }
4513: return %config;
4514: }
4515:
4516: sub username_to_idmap {
4517: my ($classlist)= @_;
4518: my %idmap;
4519: foreach my $student (keys(%$classlist)) {
4520: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4521: $student;
4522: }
4523: return %idmap;
4524: }
4525:
1.157 albertel 4526: sub scantron_fixup_scanline {
4527: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4528: if ($field eq 'ID') {
4529: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4530: return ($line,1,'New value too large');
1.157 albertel 4531: }
4532: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4533: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4534: $args->{'newid'});
4535: }
4536: substr($line,$$scantron_config{'IDstart'}-1,
4537: $$scantron_config{'IDlength'})=$args->{'newid'};
4538: if ($args->{'newid'}=~/^\s*$/) {
4539: &scan_data($scan_data,"$whichline.user",
4540: $args->{'username'}.':'.$args->{'domain'});
4541: }
1.186 albertel 4542: } elsif ($field eq 'CODE') {
1.192 albertel 4543: if ($args->{'CODE_ignore_dup'}) {
4544: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4545: }
4546: &scan_data($scan_data,"$whichline.useCODE",'1');
4547: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4548: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4549: return ($line,1,'New CODE value too large');
4550: }
4551: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4552: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4553: }
4554: substr($line,$$scantron_config{'CODEstart'}-1,
4555: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4556: }
1.157 albertel 4557: } elsif ($field eq 'answer') {
4558: my $length=$scantron_config->{'Qlength'};
4559: my $off=$scantron_config->{'Qoff'};
4560: my $on=$scantron_config->{'Qon'};
4561: my $answer=${off}x$length;
4562: if ($args->{'response'} eq 'none') {
4563: &scan_data($scan_data,
4564: "$whichline.no_bubble.".$args->{'question'},'1');
4565: } else {
1.274 albertel 4566: if ($on eq 'letter') {
4567: my @alphabet=('A'..'Z');
4568: $answer=$alphabet[$args->{'response'}];
4569: } elsif ($on eq 'number') {
4570: $answer=$args->{'response'}+1;
4571: } else {
4572: substr($answer,$args->{'response'},1)=$on;
4573: }
1.157 albertel 4574: &scan_data($scan_data,
4575: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4576: }
4577: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4578: substr($line,$where-1,$length)=$answer;
4579: }
4580: return $line;
4581: }
4582:
4583: sub scan_data {
4584: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4585: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4586: if (defined($value)) {
4587: $scan_data->{$filename.'_'.$key} = $value;
4588: }
4589: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4590: return $scan_data->{$filename.'_'.$key};
4591: }
4592:
1.82 albertel 4593: sub scantron_parse_scanline {
1.194 albertel 4594: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4595: my %record;
4596: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4597: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4598: if (!($$scantron_config{'CODElocation'} eq 0 ||
4599: $$scantron_config{'CODElocation'} eq 'none')) {
4600: if ($$scantron_config{'CODElocation'} < 0 ||
4601: $$scantron_config{'CODElocation'} eq 'letter' ||
4602: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4603: $record{'scantron.CODE'}=substr($data,
4604: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4605: $$scantron_config{'CODElength'});
1.191 albertel 4606: if (&scan_data($scan_data,"$whichline.useCODE")) {
4607: $record{'scantron.useCODE'}=1;
4608: }
1.192 albertel 4609: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4610: $record{'scantron.CODE_ignore_dup'}=1;
4611: }
1.82 albertel 4612: } else {
4613: #FIXME interpret first N questions
4614: }
4615: }
1.83 albertel 4616: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4617: $$scantron_config{'IDlength'});
1.157 albertel 4618: $record{'scantron.PaperID'}=
4619: substr($data,$$scantron_config{'PaperID'}-1,
4620: $$scantron_config{'PaperIDlength'});
4621: $record{'scantron.FirstName'}=
4622: substr($data,$$scantron_config{'FirstName'}-1,
4623: $$scantron_config{'FirstNamelength'});
4624: $record{'scantron.LastName'}=
4625: substr($data,$$scantron_config{'LastName'}-1,
4626: $$scantron_config{'LastNamelength'});
1.194 albertel 4627: if ($justHeader) { return \%record; }
4628:
1.82 albertel 4629: my @alphabet=('A'..'Z');
4630: my $questnum=0;
4631: while ($questions) {
4632: $questnum++;
4633: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4634: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4635: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4636: if ($$scantron_config{'Qon'} eq 'letter') {
1.371 albertel 4637: if ($currentquest eq '?'
4638: || $currentquest eq '*') {
1.274 albertel 4639: push(@{$record{'scantron.doubleerror'}},$questnum);
4640: $record{"scantron.$questnum.answer"}='';
4641: } elsif (!$currentquest
4642: || $currentquest eq $$scantron_config{'Qoff'}
4643: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4644: $record{"scantron.$questnum.answer"}='';
4645: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4646: push(@{$record{"scantron.missingerror"}},$questnum);
4647: }
4648: } else {
4649: $record{"scantron.$questnum.answer"}=$currentquest;
4650: }
4651: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.371 albertel 4652: if ($currentquest eq '?'
4653: || $currentquest eq '*') {
1.274 albertel 4654: push(@{$record{'scantron.doubleerror'}},$questnum);
4655: $record{"scantron.$questnum.answer"}='';
4656: } elsif (!$currentquest
4657: || $currentquest eq $$scantron_config{'Qoff'}
4658: || $currentquest !~ /^\d$/) {
1.239 albertel 4659: $record{"scantron.$questnum.answer"}='';
4660: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4661: push(@{$record{"scantron.missingerror"}},$questnum);
4662: }
4663: } else {
1.371 albertel 4664: # wrap zero back to J
4665: if ($currentquest eq '0') {
4666: $record{"scantron.$questnum.answer"}=
4667: $alphabet[9];
4668: } else {
4669: $record{"scantron.$questnum.answer"}=
4670: $alphabet[$currentquest-1];
4671: }
1.239 albertel 4672: }
1.82 albertel 4673: } else {
1.239 albertel 4674: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4675: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4676: $record{"scantron.$questnum.answer"}='';
4677: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4678: push(@{$record{"scantron.missingerror"}},$questnum);
4679: }
4680: } else {
4681: $record{"scantron.$questnum.answer"}=
4682: $alphabet[length($array[0])];
4683: }
4684: if (scalar(@array) gt 2) {
4685: push(@{$record{'scantron.doubleerror'}},$questnum);
4686: my @ans=@array;
4687: my $i=length($ans[0]);shift(@ans);
4688: while ($#ans) {
4689: $i+=length($ans[0])+1;
4690: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4691: shift(@ans);
4692: }
4693: }
1.82 albertel 4694: }
4695: }
1.83 albertel 4696: $record{'scantron.maxquest'}=$questnum;
4697: return \%record;
1.82 albertel 4698: }
4699:
4700: sub scantron_add_delay {
1.140 albertel 4701: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4702: push(@$delayqueue,
4703: {'line' => $scanline, 'emsg' => $errormessage,
4704: 'ecode' => $errorcode }
4705: );
1.82 albertel 4706: }
4707:
4708: sub scantron_find_student {
1.157 albertel 4709: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4710: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4711: if ($scanID =~ /^\s*$/) {
4712: return &scan_data($scan_data,"$line.user");
4713: }
1.83 albertel 4714: foreach my $id (keys(%$idmap)) {
1.157 albertel 4715: if (lc($id) eq lc($scanID)) {
4716: return $$idmap{$id};
4717: }
1.83 albertel 4718: }
4719: return undef;
4720: }
4721:
4722: sub scantron_filter {
4723: my ($curres)=@_;
1.331 albertel 4724:
4725: if (ref($curres) && $curres->is_problem()) {
4726: # if the user has asked to not have either hidden
4727: # or 'randomout' controlled resources to be graded
4728: # don't include them
4729: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
4730: && $curres->randomout) {
4731: return 0;
4732: }
1.83 albertel 4733: return 1;
4734: }
4735: return 0;
1.82 albertel 4736: }
4737:
1.157 albertel 4738: sub scantron_process_corrections {
4739: my ($r) = @_;
1.257 albertel 4740: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4741: my ($scanlines,$scan_data)=&scantron_getfile();
4742: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4743: my $which=$env{'form.scantron_line'};
1.200 albertel 4744: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4745: my ($skip,$err,$errmsg);
1.257 albertel 4746: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4747: $skip=1;
1.257 albertel 4748: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4749: my $newstudent=$env{'form.scantron_username'}.':'.
4750: $env{'form.scantron_domain'};
1.157 albertel 4751: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4752: ($line,$err,$errmsg)=
4753: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4754: 'ID',{'newid'=>$newid,
1.257 albertel 4755: 'username'=>$env{'form.scantron_username'},
4756: 'domain'=>$env{'form.scantron_domain'}});
4757: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4758: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4759: my $newCODE;
1.192 albertel 4760: my %args;
1.190 albertel 4761: if ($resolution eq 'use_unfound') {
1.191 albertel 4762: $newCODE='use_unfound';
1.190 albertel 4763: } elsif ($resolution eq 'use_found') {
1.257 albertel 4764: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4765: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4766: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4767: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4768: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4769: }
1.257 albertel 4770: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4771: $args{'CODE_ignore_dup'}=1;
4772: }
4773: $args{'CODE'}=$newCODE;
1.186 albertel 4774: ($line,$err,$errmsg)=
4775: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4776: 'CODE',\%args);
1.257 albertel 4777: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4778: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4779: ($line,$err,$errmsg)=
4780: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4781: $which,'answer',
4782: { 'question'=>$question,
1.257 albertel 4783: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4784: if ($err) { last; }
4785: }
4786: }
4787: if ($err) {
1.287 albertel 4788: $r->print("<font color='red'>Unable to accept last correction, an error occurred :$errmsg:</font>");
1.157 albertel 4789: } else {
1.200 albertel 4790: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4791: &scantron_putfile($scanlines,$scan_data);
4792: }
4793: }
4794:
1.200 albertel 4795: sub reset_skipping_status {
4796: my ($scanlines,$scan_data)=&scantron_getfile();
4797: &scan_data($scan_data,'remember_skipping',undef,1);
4798: &scantron_putfile(undef,$scan_data);
4799: }
4800:
1.376 albertel 4801: sub start_skipping {
1.200 albertel 4802: my ($scan_data,$i)=@_;
4803: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4804: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
4805: $remembered{$i}=2;
4806: } else {
4807: $remembered{$i}=1;
4808: }
1.200 albertel 4809: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4810: }
4811:
4812: sub should_be_skipped {
1.376 albertel 4813: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 4814: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4815: # not redoing old skips
1.376 albertel 4816: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 4817: return 0;
4818: }
4819: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4820:
4821: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
4822: return 0;
4823: }
1.200 albertel 4824: return 1;
4825: }
4826:
4827: sub remember_current_skipped {
4828: my ($scanlines,$scan_data)=&scantron_getfile();
4829: my %to_remember;
4830: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4831: if ($scanlines->{'skipped'}[$i]) {
4832: $to_remember{$i}=1;
4833: }
4834: }
1.376 albertel 4835:
1.200 albertel 4836: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4837: &scantron_putfile(undef,$scan_data);
4838: }
4839:
4840: sub check_for_error {
4841: my ($r,$result)=@_;
4842: if ($result ne 'ok' && $result ne 'not_found' ) {
4843: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4844: }
4845: }
1.157 albertel 4846:
1.203 albertel 4847: sub scantron_warning_screen {
4848: my ($button_text)=@_;
1.257 albertel 4849: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4850: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 4851: my $CODElist;
1.284 albertel 4852: if ($scantron_config{'CODElocation'} &&
4853: $scantron_config{'CODEstart'} &&
4854: $scantron_config{'CODElength'}) {
4855: $CODElist=$env{'form.scantron_CODElist'};
1.373 albertel 4856: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<font color="red">None</font>'; }
1.284 albertel 4857: $CODElist=
4858: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
1.373 albertel 4859: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 4860: }
1.203 albertel 4861: return (<<STUFF);
4862: <p>
4863: <font color="red">Please double check the information
4864: below before clicking on '$button_text'</font>
4865: </p>
4866: <table>
1.284 albertel 4867: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4868: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4869: $CODElist
1.203 albertel 4870: </table>
4871: </font>
4872: <br />
4873: <p> If this information is correct, please click on '$button_text'.</p>
4874: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4875:
4876: <br />
4877: STUFF
4878: }
4879:
4880: sub scantron_do_warning {
4881: my ($r)=@_;
1.324 albertel 4882: my ($symb)=&get_symb($r);
1.203 albertel 4883: if (!$symb) {return '';}
1.324 albertel 4884: my $default_form_data=&defaultFormData($symb);
1.203 albertel 4885: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 4886: if ( $env{'form.selectpage'} eq '' ||
4887: $env{'form.scantron_selectfile'} eq '' ||
4888: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 4889: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 4890: if ( $env{'form.selectpage'} eq '') {
1.237 albertel 4891: $r->print('<p><font color="red">You have not selected a Sequence to grade</font></p>');
4892: }
1.257 albertel 4893: if ( $env{'form.scantron_selectfile'} eq '') {
1.237 albertel 4894: $r->print('<p><font color="red">You have not selected a file that contains the student\'s response data.</font></p>');
4895: }
1.257 albertel 4896: if ( $env{'form.scantron_format'} eq '') {
1.237 albertel 4897: $r->print('<p><font color="red">You have not selected a the format of the student\'s response data.</font></p>');
4898: }
4899: } else {
1.265 www 4900: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 4901: $r->print(<<STUFF);
1.203 albertel 4902: $warning
1.265 www 4903: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 4904: <input type="hidden" name="command" value="scantron_validate" />
4905: STUFF
1.237 albertel 4906: }
1.352 albertel 4907: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 4908: return '';
4909: }
4910:
4911: sub scantron_form_start {
4912: my ($max_bubble)=@_;
4913: my $result= <<SCANTRONFORM;
4914: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 4915: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
4916: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
4917: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 4918: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 4919: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
4920: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
4921: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
4922: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 4923: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 4924: SCANTRONFORM
4925: return $result;
4926: }
4927:
1.157 albertel 4928: sub scantron_validate_file {
4929: my ($r) = @_;
1.324 albertel 4930: my ($symb)=&get_symb($r);
1.157 albertel 4931: if (!$symb) {return '';}
1.324 albertel 4932: my $default_form_data=&defaultFormData($symb);
1.200 albertel 4933:
4934: # do the detection of only doing skipped records first befroe we delete
4935: # them when doing the corrections reset
1.257 albertel 4936: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 4937: &reset_skipping_status();
4938: }
1.257 albertel 4939: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 4940: &remember_current_skipped();
1.257 albertel 4941: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 4942: }
4943:
1.257 albertel 4944: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 4945: &check_for_error($r,&scantron_remove_file('corrected'));
4946: &check_for_error($r,&scantron_remove_file('skipped'));
4947: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 4948: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 4949: }
1.200 albertel 4950:
1.257 albertel 4951: if ($env{'form.scantron_corrections'}) {
1.157 albertel 4952: &scantron_process_corrections($r);
4953: }
1.191 albertel 4954: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 4955: #get the student pick code ready
4956: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 4957: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 4958: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 4959: $r->print($result);
4960:
1.334 albertel 4961: my @validate_phases=( 'sequence',
4962: 'ID',
1.157 albertel 4963: 'CODE',
4964: 'doublebubble',
4965: 'missingbubbles');
1.257 albertel 4966: if (!$env{'form.validatepass'}) {
4967: $env{'form.validatepass'} = 0;
1.157 albertel 4968: }
1.257 albertel 4969: my $currentphase=$env{'form.validatepass'};
1.157 albertel 4970:
4971: my $stop=0;
4972: while (!$stop && $currentphase < scalar(@validate_phases)) {
4973: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
4974: $r->rflush();
4975: my $which="scantron_validate_".$validate_phases[$currentphase];
4976: {
4977: no strict 'refs';
4978: ($stop,$currentphase)=&$which($r,$currentphase);
4979: }
4980: }
4981: if (!$stop) {
1.203 albertel 4982: my $warning=&scantron_warning_screen('Start Grading');
4983: $r->print(<<STUFF);
4984: Validation process complete.<br />
4985: $warning
4986: <input type="submit" name="submit" value="Start Grading" />
4987: <input type="hidden" name="command" value="scantron_process" />
4988: STUFF
4989:
1.157 albertel 4990: } else {
4991: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
4992: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
4993: }
4994: if ($stop) {
1.334 albertel 4995: if ($validate_phases[$currentphase] eq 'sequence') {
4996: $r->print('<input type="submit" name="submit" value="Ignore -> " />');
4997: $r->print(' this error <br />');
4998:
4999: $r->print(" <p>Or click the 'Grading Menu' button to start over.</p>");
5000: } else {
5001: $r->print('<input type="submit" name="submit" value="Continue ->" />');
5002: $r->print(' using corrected info <br />');
5003: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
5004: $r->print(" this scanline saving it for later.");
5005: }
1.157 albertel 5006: }
1.352 albertel 5007: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 5008: return '';
5009: }
5010:
1.200 albertel 5011: sub scantron_remove_file {
1.192 albertel 5012: my ($which)=@_;
1.257 albertel 5013: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5014: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5015: my $file='scantron_';
1.200 albertel 5016: if ($which eq 'corrected' || $which eq 'skipped') {
5017: $file.=$which.'_';
1.192 albertel 5018: } else {
5019: return 'refused';
5020: }
1.257 albertel 5021: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 5022: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
5023: }
5024:
5025: sub scantron_remove_scan_data {
1.257 albertel 5026: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5027: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5028: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
5029: my @todelete;
1.257 albertel 5030: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 5031: foreach my $key (@keys) {
5032: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 5033: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 5034: $key=~/remember_skipping/) {
5035: next;
5036: }
1.192 albertel 5037: push(@todelete,$key);
5038: }
5039: }
1.200 albertel 5040: my $result;
1.192 albertel 5041: if (@todelete) {
1.200 albertel 5042: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 5043: }
5044: return $result;
5045: }
5046:
1.157 albertel 5047: sub scantron_getfile {
1.200 albertel 5048: #FIXME really would prefer a scantron directory
1.257 albertel 5049: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5050: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 5051: my $lines;
5052: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5053: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 5054: my %scanlines;
5055: $scanlines{'orig'}=[(split("\n",$lines,-1))];
5056: my $temp=$scanlines{'orig'};
5057: $scanlines{'count'}=$#$temp;
5058:
5059: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5060: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 5061: if ($lines eq '-1') {
5062: $scanlines{'corrected'}=[];
5063: } else {
5064: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
5065: }
5066: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5067: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 5068: if ($lines eq '-1') {
5069: $scanlines{'skipped'}=[];
5070: } else {
5071: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
5072: }
1.175 albertel 5073: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 5074: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
5075: my %scan_data = @tmp;
5076: return (\%scanlines,\%scan_data);
5077: }
5078:
5079: sub lonnet_putfile {
5080: my ($contents,$filename)=@_;
1.257 albertel 5081: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5082: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5083: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 5084: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 5085:
5086: }
5087:
5088: sub scantron_putfile {
5089: my ($scanlines,$scan_data) = @_;
1.200 albertel 5090: #FIXME really would prefer a scantron directory
1.257 albertel 5091: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5092: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 5093: if ($scanlines) {
5094: my $prefix='scantron_';
1.157 albertel 5095: # no need to update orig, shouldn't change
5096: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 5097: # $env{'form.scantron_selectfile'});
1.200 albertel 5098: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
5099: $prefix.'corrected_'.
1.257 albertel 5100: $env{'form.scantron_selectfile'});
1.200 albertel 5101: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
5102: $prefix.'skipped_'.
1.257 albertel 5103: $env{'form.scantron_selectfile'});
1.200 albertel 5104: }
1.175 albertel 5105: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 5106: }
5107:
5108: sub scantron_get_line {
1.200 albertel 5109: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 5110: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
5111: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 5112: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
5113: return $scanlines->{'orig'}[$i];
5114: }
5115:
1.200 albertel 5116: sub get_todo_count {
5117: my ($scanlines,$scan_data)=@_;
5118: my $count=0;
5119: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5120: my $line=&scantron_get_line($scanlines,$scan_data,$i);
5121: if ($line=~/^[\s\cz]*$/) { next; }
5122: $count++;
5123: }
5124: return $count;
5125: }
5126:
1.157 albertel 5127: sub scantron_put_line {
1.200 albertel 5128: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 5129: if ($skip) {
5130: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 5131: &start_skipping($scan_data,$i);
1.157 albertel 5132: return;
5133: }
5134: $scanlines->{'corrected'}[$i]=$newline;
5135: }
5136:
1.376 albertel 5137: sub scantron_clear_skip {
5138: my ($scanlines,$scan_data,$i)=@_;
5139: if (exists($scanlines->{'skipped'}[$i])) {
5140: undef($scanlines->{'skipped'}[$i]);
5141: return 1;
5142: }
5143: return 0;
5144: }
5145:
1.334 albertel 5146: sub scantron_filter_not_exam {
5147: my ($curres)=@_;
5148:
5149: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
5150: # if the user has asked to not have either hidden
5151: # or 'randomout' controlled resources to be graded
5152: # don't include them
5153: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5154: && $curres->randomout) {
5155: return 0;
5156: }
5157: return 1;
5158: }
5159: return 0;
5160: }
5161:
5162: sub scantron_validate_sequence {
5163: my ($r,$currentphase) = @_;
5164:
5165: my $navmap=Apache::lonnavmaps::navmap->new();
5166: my (undef,undef,$sequence)=
5167: &Apache::lonnet::decode_symb($env{'form.selectpage'});
5168:
5169: my $map=$navmap->getResourceByUrl($sequence);
5170:
5171: $r->print('<input type="hidden" name="validate_sequence_exam"
5172: value="ignore" />');
5173: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
5174: my @resources=
5175: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
5176: if (@resources) {
1.357 banghart 5177: $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 5178: return (1,$currentphase);
5179: }
5180: }
5181:
5182: return (0,$currentphase+1);
5183: }
5184:
1.157 albertel 5185: sub scantron_validate_ID {
5186: my ($r,$currentphase) = @_;
5187:
5188: #get student info
5189: my $classlist=&Apache::loncoursedata::get_classlist();
5190: my %idmap=&username_to_idmap($classlist);
5191:
5192: #get scantron line setup
1.257 albertel 5193: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5194: my ($scanlines,$scan_data)=&scantron_getfile();
5195:
5196: my %found=('ids'=>{},'usernames'=>{});
5197: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5198: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5199: if ($line=~/^[\s\cz]*$/) { next; }
5200: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5201: $scan_data);
5202: my $id=$$scan_record{'scantron.ID'};
5203: my $found;
5204: foreach my $checkid (keys(%idmap)) {
5205: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
5206: }
5207: if ($found) {
5208: my $username=$idmap{$found};
5209: if ($found{'ids'}{$found}) {
5210: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5211: $line,'duplicateID',$found);
1.194 albertel 5212: return(1,$currentphase);
1.157 albertel 5213: } elsif ($found{'usernames'}{$username}) {
5214: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5215: $line,'duplicateID',$username);
1.194 albertel 5216: return(1,$currentphase);
1.157 albertel 5217: }
1.186 albertel 5218: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 5219: $found{'ids'}{$found}++;
5220: $found{'usernames'}{$username}++;
5221: } else {
5222: if ($id =~ /^\s*$/) {
1.158 albertel 5223: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 5224: if (defined($username) && $found{'usernames'}{$username}) {
5225: &scantron_get_correction($r,$i,$scan_record,
5226: \%scantron_config,
5227: $line,'duplicateID',$username);
1.194 albertel 5228: return(1,$currentphase);
1.157 albertel 5229: } elsif (!defined($username)) {
5230: &scantron_get_correction($r,$i,$scan_record,
5231: \%scantron_config,
5232: $line,'incorrectID');
1.194 albertel 5233: return(1,$currentphase);
1.157 albertel 5234: }
5235: $found{'usernames'}{$username}++;
5236: } else {
5237: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5238: $line,'incorrectID');
1.194 albertel 5239: return(1,$currentphase);
1.157 albertel 5240: }
5241: }
5242: }
5243:
5244: return (0,$currentphase+1);
5245: }
5246:
5247: sub scantron_get_correction {
5248: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
5249:
5250: #FIXME in the case of a duplicated ID the previous line, probaly need
5251: #to show both the current line and the previous one and allow skipping
5252: #the previous one or the current one
5253:
1.161 albertel 5254: $r->print("<p><b>An error was detected ($error)</b>");
1.333 albertel 5255: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.157 albertel 5256: $r->print(" for PaperID <tt>".
5257: $$scan_record{'scantron.PaperID'}."</tt> \n");
5258: } else {
5259: $r->print(" in scanline $i <pre>".
5260: $line."</pre> \n");
5261: }
1.242 albertel 5262: my $message="<p>The ID on the form is <tt>".
5263: $$scan_record{'scantron.ID'}."</tt><br />\n".
5264: "The name on the paper is ".
5265: $$scan_record{'scantron.LastName'}.",".
5266: $$scan_record{'scantron.FirstName'}."</p>";
5267:
1.157 albertel 5268: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
5269: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
5270: if ($error =~ /ID$/) {
1.186 albertel 5271: if ($error eq 'incorrectID') {
1.157 albertel 5272: $r->print("The encoded ID is not in the classlist</p>\n");
5273: } elsif ($error eq 'duplicateID') {
5274: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
5275: }
1.242 albertel 5276: $r->print($message);
1.157 albertel 5277: $r->print("<p>How should I handle this? <br /> \n");
5278: $r->print("\n<ul><li> ");
5279: #FIXME it would be nice if this sent back the user ID and
5280: #could do partial userID matches
5281: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
5282: 'scantron_username','scantron_domain'));
5283: $r->print(": <input type='text' name='scantron_username' value='' />");
5284: $r->print("\n@".
1.257 albertel 5285: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 5286:
5287: $r->print('</li>');
1.186 albertel 5288: } elsif ($error =~ /CODE$/) {
5289: if ($error eq 'incorrectCODE') {
1.187 albertel 5290: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5291: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5292: $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 5293: }
1.224 albertel 5294: $r->print("<p>The CODE on the form is <tt>'".
5295: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5296: $r->print($message);
1.186 albertel 5297: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5298: $r->print("\n<br /> ");
1.194 albertel 5299: my $i=0;
1.273 albertel 5300: if ($error eq 'incorrectCODE'
5301: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5302: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5303: if ($closest > 0) {
5304: foreach my $testcode (@{$closest}) {
5305: my $checked='';
5306: if (!$i) { $checked=' checked="on" '; }
5307: $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' />");
5308: $r->print("\n<br />");
5309: $i++;
5310: }
1.194 albertel 5311: }
5312: }
1.273 albertel 5313: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5314: my $checked; if (!$i) { $checked=' checked="on" '; }
5315: $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>");
5316: $r->print("\n<br />");
5317: }
1.194 albertel 5318:
1.188 albertel 5319: $r->print(<<ENDSCRIPT);
5320: <script type="text/javascript">
5321: function change_radio(field) {
1.190 albertel 5322: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5323: var i;
5324: for (i=0;i<slct.length;i++) {
5325: if (slct[i].value==field) { slct[i].checked=true; }
5326: }
5327: }
5328: </script>
5329: ENDSCRIPT
1.187 albertel 5330: my $href="/adm/pickcode?".
1.359 www 5331: "form=".&escape("scantronupload").
5332: "&scantron_format=".&escape($env{'form.scantron_format'}).
5333: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
5334: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
5335: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 5336: if ($env{'form.scantron_CODElist'} =~ /\S/) {
5337: $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')\" />");
5338: $r->print("\n<br />");
5339: }
1.272 albertel 5340: $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 5341: $r->print("\n<br /><br />");
1.157 albertel 5342: } elsif ($error eq 'doublebubble') {
5343: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5344: $r->print('<input type="hidden" name="scantron_questions" value="'.
5345: join(',',@{$arg}).'" />');
1.242 albertel 5346: $r->print($message);
1.157 albertel 5347: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5348: foreach my $question (@{$arg}) {
5349: my $selected=$$scan_record{"scantron.$question.answer"};
5350: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5351: }
5352: } elsif ($error eq 'missingbubble') {
5353: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5354: $r->print($message);
1.157 albertel 5355: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5356: $r->print("Some questions have no scanned bubbles\n");
5357: $r->print('<input type="hidden" name="scantron_questions" value="'.
5358: join(',',@{$arg}).'" />');
5359: foreach my $question (@{$arg}) {
5360: my $selected=$$scan_record{"scantron.$question.answer"};
5361: &scantron_bubble_selector($r,$scan_config,$question);
5362: }
5363: } else {
5364: $r->print("\n<ul>");
5365: }
5366: $r->print("\n</li></ul>");
5367:
5368: }
5369:
5370: sub scantron_bubble_selector {
5371: my ($r,$scan_config,$quest,@selected)=@_;
5372: my $max=$$scan_config{'Qlength'};
1.274 albertel 5373:
5374: my $scmode=$$scan_config{'Qon'};
5375: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5376:
1.157 albertel 5377: my @alphabet=('A'..'Z');
5378: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5379: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5380: $r->print("\n".'<td align="center">');
1.157 albertel 5381: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5382: else { $r->print(' '); }
5383: $r->print('</td>');
5384: }
1.274 albertel 5385: $r->print('</tr><tr>');
1.157 albertel 5386: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5387: $r->print("\n".
5388: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5389: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5390: }
1.272 albertel 5391: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5392: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5393: $r->print('</tr></table>');
5394: }
5395:
1.194 albertel 5396: sub num_matches {
5397: my ($orig,$code) = @_;
5398: my @code=split(//,$code);
5399: my @orig=split(//,$orig);
5400: my $same=0;
5401: for (my $i=0;$i<scalar(@code);$i++) {
5402: if ($code[$i] eq $orig[$i]) { $same++; }
5403: }
5404: return $same;
5405: }
5406:
5407: sub scantron_get_closely_matching_CODEs {
5408: my ($allcodes,$CODE)=@_;
5409: my @CODEs;
5410: foreach my $testcode (sort(keys(%{$allcodes}))) {
5411: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5412: }
5413:
5414: return ($#CODEs,$CODEs[-1]);
5415: }
5416:
5417: sub get_codes {
1.280 foxr 5418: my ($old_name, $cdom, $cnum) = @_;
5419: if (!$old_name) {
5420: $old_name=$env{'form.scantron_CODElist'};
5421: }
5422: if (!$cdom) {
5423: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5424: }
5425: if (!$cnum) {
5426: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5427: }
1.278 albertel 5428: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5429: $cdom,$cnum);
5430: my %allcodes;
5431: if ($result{"type\0$old_name"} eq 'number') {
5432: %allcodes=map {($_,1)} split(',',$result{$old_name});
5433: } else {
5434: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5435: }
1.194 albertel 5436: return %allcodes;
5437: }
5438:
1.157 albertel 5439: sub scantron_validate_CODE {
5440: my ($r,$currentphase) = @_;
1.257 albertel 5441: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5442: if ($scantron_config{'CODElocation'} &&
5443: $scantron_config{'CODEstart'} &&
5444: $scantron_config{'CODElength'}) {
1.257 albertel 5445: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5446: &FIXME_blow_up()
5447: }
5448: } else {
5449: return (0,$currentphase+1);
5450: }
5451:
5452: my %usedCODEs;
5453:
1.194 albertel 5454: my %allcodes=&get_codes();
1.186 albertel 5455:
5456: my ($scanlines,$scan_data)=&scantron_getfile();
5457: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5458: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5459: if ($line=~/^[\s\cz]*$/) { next; }
5460: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5461: $scan_data);
5462: my $CODE=$$scan_record{'scantron.CODE'};
5463: my $error=0;
1.224 albertel 5464: if (!&Apache::lonnet::validCODE($CODE)) {
5465: &scantron_get_correction($r,$i,$scan_record,
5466: \%scantron_config,
5467: $line,'incorrectCODE',\%allcodes);
5468: return(1,$currentphase);
5469: }
1.221 albertel 5470: if (%allcodes && !exists($allcodes{$CODE})
5471: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5472: &scantron_get_correction($r,$i,$scan_record,
5473: \%scantron_config,
1.194 albertel 5474: $line,'incorrectCODE',\%allcodes);
5475: return(1,$currentphase);
1.186 albertel 5476: }
1.214 albertel 5477: if (exists($usedCODEs{$CODE})
1.257 albertel 5478: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5479: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5480: &scantron_get_correction($r,$i,$scan_record,
5481: \%scantron_config,
1.194 albertel 5482: $line,'duplicateCODE',$usedCODEs{$CODE});
5483: return(1,$currentphase);
1.186 albertel 5484: }
1.194 albertel 5485: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5486: }
1.157 albertel 5487: return (0,$currentphase+1);
5488: }
5489:
5490: sub scantron_validate_doublebubble {
5491: my ($r,$currentphase) = @_;
5492: #get student info
5493: my $classlist=&Apache::loncoursedata::get_classlist();
5494: my %idmap=&username_to_idmap($classlist);
5495:
5496: #get scantron line setup
1.257 albertel 5497: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5498: my ($scanlines,$scan_data)=&scantron_getfile();
5499: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5500: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5501: if ($line=~/^[\s\cz]*$/) { next; }
5502: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5503: $scan_data);
5504: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5505: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5506: 'doublebubble',
5507: $$scan_record{'scantron.doubleerror'});
5508: return (1,$currentphase);
5509: }
5510: return (0,$currentphase+1);
5511: }
5512:
1.330 albertel 5513: sub scantron_get_maxbubble {
1.257 albertel 5514: if (defined($env{'form.scantron_maxbubble'}) &&
5515: $env{'form.scantron_maxbubble'}) {
5516: return $env{'form.scantron_maxbubble'};
1.191 albertel 5517: }
1.330 albertel 5518:
1.191 albertel 5519: my $navmap=Apache::lonnavmaps::navmap->new();
5520: my (undef,undef,$sequence)=
1.257 albertel 5521: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 5522:
1.191 albertel 5523: my $map=$navmap->getResourceByUrl($sequence);
5524: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 5525:
5526: &Apache::lonxml::clear_problem_counter();
5527:
1.191 albertel 5528: foreach my $resource (@resources) {
1.330 albertel 5529: my $result=&Apache::lonnet::ssi($resource->src(),
5530: ('symb' => $resource->symb()));
1.191 albertel 5531: }
5532: &Apache::lonnet::delenv('scantron\.');
1.330 albertel 5533: $env{'form.scantron_maxbubble'} =
5534: &Apache::lonxml::get_problem_counter()-1;
5535:
1.257 albertel 5536: return $env{'form.scantron_maxbubble'};
1.191 albertel 5537: }
5538:
1.157 albertel 5539: sub scantron_validate_missingbubbles {
5540: my ($r,$currentphase) = @_;
5541: #get student info
5542: my $classlist=&Apache::loncoursedata::get_classlist();
5543: my %idmap=&username_to_idmap($classlist);
5544:
5545: #get scantron line setup
1.257 albertel 5546: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5547: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5548: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5549: if (!$max_bubble) { $max_bubble=2**31; }
5550: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5551: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5552: if ($line=~/^[\s\cz]*$/) { next; }
5553: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5554: $scan_data);
5555: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5556: my @to_correct;
5557: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5558: if ($missing > $max_bubble) { next; }
5559: push(@to_correct,$missing);
5560: }
5561: if (@to_correct) {
5562: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5563: $line,'missingbubble',\@to_correct);
5564: return (1,$currentphase);
5565: }
5566:
5567: }
5568: return (0,$currentphase+1);
5569: }
5570:
1.82 albertel 5571: sub scantron_process_students {
1.75 albertel 5572: my ($r) = @_;
1.257 albertel 5573: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 5574: my ($symb)=&get_symb($r);
1.81 albertel 5575: if (!$symb) {return '';}
1.324 albertel 5576: my $default_form_data=&defaultFormData($symb);
1.82 albertel 5577:
1.257 albertel 5578: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5579: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5580: my $classlist=&Apache::loncoursedata::get_classlist();
5581: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5582: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5583: my $map=$navmap->getResourceByUrl($sequence);
5584: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5585: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5586: my $result= <<SCANTRONFORM;
1.81 albertel 5587: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5588: <input type="hidden" name="command" value="scantron_configphase" />
5589: $default_form_data
5590: SCANTRONFORM
1.82 albertel 5591: $r->print($result);
5592:
5593: my @delayqueue;
1.140 albertel 5594: my %completedstudents;
5595:
1.200 albertel 5596: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5597: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5598: 'Scantron Progress',$count,
1.195 albertel 5599: 'inline',undef,'scantronupload');
1.140 albertel 5600: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5601: 'Processing first student');
5602: my $start=&Time::HiRes::time();
1.158 albertel 5603: my $i=-1;
1.200 albertel 5604: my ($uname,$udom,$started);
1.157 albertel 5605: while ($i<$scanlines->{'count'}) {
5606: ($uname,$udom)=('','');
5607: $i++;
1.200 albertel 5608: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5609: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5610: if ($started) {
5611: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5612: 'last student');
5613: }
5614: $started=1;
1.157 albertel 5615: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5616: $scan_data);
5617: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5618: \%idmap,$i)) {
5619: &scantron_add_delay(\@delayqueue,$line,
5620: 'Unable to find a student that matches',1);
5621: next;
5622: }
5623: if (exists $completedstudents{$uname}) {
5624: &scantron_add_delay(\@delayqueue,$line,
5625: 'Student '.$uname.' has multiple sheets',2);
5626: next;
5627: }
5628: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 5629:
5630: &Apache::lonxml::clear_problem_counter();
1.157 albertel 5631: &Apache::lonnet::appenv(%$scan_record);
1.376 albertel 5632:
5633: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
5634: &scantron_putfile($scanlines,$scan_data);
5635: }
1.161 albertel 5636:
5637: my $i=0;
1.83 albertel 5638: foreach my $resource (@resources) {
1.85 albertel 5639: $i++;
1.193 albertel 5640: my %form=('submitted' =>'scantron',
5641: 'grade_target' =>'grade',
5642: 'grade_username'=>$uname,
5643: 'grade_domain' =>$udom,
1.257 albertel 5644: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5645: 'grade_symb' =>$resource->symb());
5646: if (exists($scan_record->{'scantron.CODE'}) &&
5647: $scan_record->{'scantron.CODE'}) {
5648: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5649: } else {
5650: $form{'CODE'}='';
1.193 albertel 5651: }
5652: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5653: if ($result ne '') {
5654: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5655: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5656: }
1.213 albertel 5657: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5658: }
1.140 albertel 5659: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5660: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5661: } continue {
1.330 albertel 5662: &Apache::lonxml::clear_problem_counter();
1.83 albertel 5663: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5664: }
1.140 albertel 5665: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5666: # my $lasttime = &Time::HiRes::time()-$start;
5667: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5668:
1.200 albertel 5669: $r->print("</form>");
1.324 albertel 5670: $r->print(&show_grading_menu_form($symb));
1.157 albertel 5671: return '';
1.75 albertel 5672: }
1.157 albertel 5673:
5674: sub scantron_upload_scantron_data {
5675: my ($r)=@_;
1.257 albertel 5676: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5677: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5678: 'domainid',
5679: 'coursename');
1.257 albertel 5680: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5681: 'domainid');
1.324 albertel 5682: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.157 albertel 5683: $r->print(<<UPLOAD);
5684: <script type="text/javascript" language="javascript">
5685: function checkUpload(formname) {
5686: if (formname.upfile.value == "") {
5687: alert("Please use the browse button to select a file from your local directory.");
5688: return false;
5689: }
5690: formname.submit();
5691: }
5692: </script>
5693:
5694: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5695: $default_form_data
1.181 albertel 5696: <table>
5697: <tr><td>$select_link </td></tr>
5698: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5699: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5700: <tr><td>Domain: </td><td>$domsel </td></tr>
5701: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5702: </table>
1.157 albertel 5703: <input name='command' value='scantronupload_save' type='hidden' />
5704: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5705: </form>
5706: UPLOAD
5707: return '';
5708: }
5709:
5710: sub scantron_upload_scantron_data_save {
5711: my($r)=@_;
1.324 albertel 5712: my ($symb)=&get_symb($r,1);
1.182 albertel 5713: my $doanotherupload=
5714: '<br /><form action="/adm/grades" method="post">'."\n".
5715: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5716: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5717: '</form>'."\n";
1.257 albertel 5718: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5719: !&Apache::lonnet::allowed('usc',
1.257 albertel 5720: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5721: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5722: if ($symb) {
1.324 albertel 5723: $r->print(&show_grading_menu_form($symb));
1.182 albertel 5724: } else {
5725: $r->print($doanotherupload);
5726: }
1.162 albertel 5727: return '';
5728: }
1.257 albertel 5729: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5730: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5731: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5732: #FIXME
5733: #copied from lonnet::userfileupload()
5734: #make that function able to target a specified course
5735: # Replace Windows backslashes by forward slashes
5736: $fname=~s/\\/\//g;
5737: # Get rid of everything but the actual filename
5738: $fname=~s/^.*\/([^\/]+)$/$1/;
5739: # Replace spaces by underscores
5740: $fname=~s/\s+/\_/g;
5741: # Replace all other weird characters by nothing
5742: $fname=~s/[^\w\.\-]//g;
5743: # See if there is anything left
5744: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5745: my $uploadedfile=$fname;
1.157 albertel 5746: $fname='scantron_orig_'.$fname;
1.257 albertel 5747: if (length($env{'form.upfile'}) < 2) {
5748: $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 5749: } else {
1.275 albertel 5750: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5751: if ($result =~ m|^/uploaded/|) {
1.257 albertel 5752: $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 5753: } else {
1.257 albertel 5754: $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 5755: }
5756: }
1.174 albertel 5757: if ($symb) {
1.209 ng 5758: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5759: } else {
1.182 albertel 5760: $r->print($doanotherupload);
1.174 albertel 5761: }
1.157 albertel 5762: return '';
5763: }
5764:
1.202 albertel 5765: sub valid_file {
5766: my ($requested_file)=@_;
5767: foreach my $filename (sort(&scantron_filenames())) {
5768: if ($requested_file eq $filename) { return 1; }
5769: }
5770: return 0;
5771: }
5772:
5773: sub scantron_download_scantron_data {
5774: my ($r)=@_;
1.324 albertel 5775: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5776: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5777: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5778: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5779: if (! &valid_file($file)) {
5780: $r->print(<<ERROR);
5781: <p>
5782: The requested file name was invalid.
5783: </p>
5784: ERROR
1.324 albertel 5785: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5786: return;
5787: }
5788: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5789: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5790: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5791: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5792: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5793: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5794: $r->print(<<DOWNLOAD);
5795: <p>
5796: <a href="$orig">Original</a> file as uploaded by the scantron office.
5797: </p>
5798: <p>
5799: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5800: </p>
5801: <p>
5802: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5803: </p>
5804: DOWNLOAD
1.324 albertel 5805: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5806: return '';
5807: }
1.157 albertel 5808:
1.75 albertel 5809: #-------- end of section for handling grading scantron forms -------
5810: #
5811: #-------------------------------------------------------------------
5812:
1.72 ng 5813: #-------------------------- Menu interface -------------------------
5814: #
5815: #--- Show a Grading Menu button - Calls the next routine ---
5816: sub show_grading_menu_form {
1.324 albertel 5817: my ($symb)=@_;
1.125 ng 5818: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 5819: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 5820: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5821: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5822: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5823: '</form>'."\n";
5824: return $result;
5825: }
5826:
1.77 ng 5827: # -- Retrieve choices for grading form
5828: sub savedState {
5829: my %savedState = ();
1.257 albertel 5830: if ($env{'form.saveState'}) {
5831: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5832: my ($key,$value) = split(/=/,$_,2);
5833: $savedState{$key} = $value;
5834: }
5835: }
5836: return \%savedState;
5837: }
1.76 ng 5838:
1.72 ng 5839: #--- Displays the main menu page -------
5840: sub gradingmenu {
5841: my ($request) = @_;
1.324 albertel 5842: my ($symb)=&get_symb($request);
1.72 ng 5843: if (!$symb) {return '';}
1.76 ng 5844: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5845:
5846: $request->print(<<GRADINGMENUJS);
5847: <script type="text/javascript" language="javascript">
1.116 ng 5848: function checkChoice(formname,val,cmdx) {
5849: if (val <= 2) {
5850: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5851: var cmdsave = cmd;
1.116 ng 5852: } else {
5853: cmd = cmdx;
1.118 ng 5854: cmdsave = 'submission';
1.116 ng 5855: }
5856: formname.command.value = cmd;
1.118 ng 5857: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5858: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5859: if (val < 5) formname.submit();
5860: if (val == 5) {
1.72 ng 5861: if (!checkReceiptNo(formname,'notOK')) { return false;}
5862: formname.submit();
5863: }
1.238 albertel 5864: if (val < 7) formname.submit();
1.72 ng 5865: }
5866:
5867: function checkReceiptNo(formname,nospace) {
5868: var receiptNo = formname.receipt.value;
5869: var checkOpt = false;
5870: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5871: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5872: if (checkOpt) {
5873: alert("Please enter a receipt number given by a student in the receipt box.");
5874: formname.receipt.value = "";
5875: formname.receipt.focus();
5876: return false;
5877: }
5878: return true;
5879: }
5880: </script>
5881: GRADINGMENUJS
1.118 ng 5882: &commonJSfunctions($request);
5883: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.324 albertel 5884: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.118 ng 5885: $result.=$table;
1.76 ng 5886: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 5887: my $savedState = &savedState();
1.118 ng 5888: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 5889: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 5890: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 5891: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 5892:
5893: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
5894: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5895: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
5896: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 5897: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 5898: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 5899: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 5900: '<input type="hidden" name="showgrading" value="yes" />'."\n";
5901:
1.326 albertel 5902: $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
5903: '<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 5904: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 5905: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
5906:
1.326 albertel 5907: $result.='<table width="100%" border="0">';
1.116 ng 5908: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 5909: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 5910: if (ref($sections)) {
1.155 albertel 5911: foreach (sort (@$sections)) {
5912: $result.='<option value="'.$_.'" '.
5913: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
5914: }
1.116 ng 5915: }
1.238 albertel 5916: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 5917:
1.167 sakharuk 5918: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 5919:
1.116 ng 5920: $result.='</td></tr>';
5921:
1.288 albertel 5922: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 5923: '<input type="radio" name="radioChoice" value="submission" '.
1.326 albertel 5924: ($saveCmd eq 'submission' ? 'checked' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 5925: '</label> <select name="submitonly">'.
1.145 albertel 5926: '<option value="yes" '.
1.326 albertel 5927: ($saveSub eq 'yes' ? 'selected="on"' : '').' />'.&mt('with submissions').'</option>'.
1.301 albertel 5928: '<option value="queued" '.
1.326 albertel 5929: ($saveSub eq 'queued' ? 'selected="on"' : '').' />'.&mt('in grading queue').'</option>'.
1.145 albertel 5930: '<option value="graded" '.
1.326 albertel 5931: ($saveSub eq 'graded' ? 'selected="on"' : '').' />'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 5932: '<option value="incorrect" '.
1.326 albertel 5933: ($saveSub eq 'incorrect' ? 'selected="on"' : '').' />'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 5934: '<option value="all" '.
1.326 albertel 5935: ($saveSub eq 'all' ? 'selected="on"' : '').' />'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 5936:
1.116 ng 5937: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 5938: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.326 albertel 5939: ($saveCmd eq 'viewgrades' ? 'checked' : '').' /> '.
1.288 albertel 5940: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 5941:
1.118 ng 5942: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 5943: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.326 albertel 5944: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').' /> '.
1.288 albertel 5945: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 5946:
1.116 ng 5947: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 5948: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 5949: '</td></tr></table>'."\n";
5950:
5951: $result.='</td><td valign="top">';
5952:
1.326 albertel 5953: $result.='<table width="100%" border="0">';
1.116 ng 5954: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 5955: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
5956: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 5957:
1.75 albertel 5958: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 5959: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 5960: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 5961:
1.257 albertel 5962: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 5963: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 5964: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
5965: ' '.&mt('receipt').': '.
1.257 albertel 5966: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.326 albertel 5967: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
1.72 ng 5968: '</td></tr>'."\n";
5969: }
1.238 albertel 5970: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5971: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
5972: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 5973: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5974: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
5975: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 5976:
1.116 ng 5977: $result.='</form></td></tr></table>'."\n".
1.72 ng 5978: '</td></tr></table>'."\n".
5979: '</td></tr></table>'."\n";
1.44 ng 5980: return $result;
1.2 albertel 5981: }
5982:
1.285 albertel 5983: sub reset_perm {
5984: undef(%perm);
5985: }
5986:
5987: sub init_perm {
5988: &reset_perm();
1.300 albertel 5989: foreach my $test_perm ('vgr','mgr','opa') {
5990:
5991: my $scope = $env{'request.course.id'};
5992: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
5993:
5994: $scope .= '/'.$env{'request.course.sec'};
5995: if ( $perm{$test_perm}=
5996: &Apache::lonnet::allowed($test_perm,$scope)) {
5997: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
5998: } else {
5999: delete($perm{$test_perm});
6000: }
1.285 albertel 6001: }
6002: }
6003: }
6004:
1.1 albertel 6005: sub handler {
1.41 ng 6006: my $request=$_[0];
1.102 albertel 6007:
1.285 albertel 6008: &reset_perm();
1.257 albertel 6009: if ($env{'browser.mathml'}) {
1.141 www 6010: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 6011: } else {
1.141 www 6012: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 6013: }
6014: $request->send_http_header;
1.44 ng 6015: return '' if $request->header_only;
1.41 ng 6016: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 6017: my $symb=&get_symb($request,1);
1.160 albertel 6018: my @commands=&Apache::loncommon::get_env_multiple('form.command');
6019: my $command=$commands[0];
6020: if ($#commands > 0) {
6021: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
6022: }
1.353 albertel 6023: $request->print(&Apache::loncommon::start_page('Grading'));
1.324 albertel 6024: if ($symb eq '' && $command eq '') {
1.257 albertel 6025: if ($env{'user.adv'}) {
6026: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
6027: ($env{'form.codethree'})) {
6028: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
6029: $env{'form.codethree'};
1.41 ng 6030: my ($tsymb,$tuname,$tudom,$tcrsid)=
6031: &Apache::lonnet::checkin($token);
6032: if ($tsymb) {
1.137 albertel 6033: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 6034: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 6035: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
6036: ('grade_username' => $tuname,
6037: 'grade_domain' => $tudom,
6038: 'grade_courseid' => $tcrsid,
6039: 'grade_symb' => $tsymb)));
1.41 ng 6040: } else {
1.45 ng 6041: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 6042: }
1.41 ng 6043: } else {
1.45 ng 6044: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 6045: }
1.14 www 6046: } else {
1.41 ng 6047: $request->print(&Apache::lonxml::tokeninputfield());
6048: }
6049: }
6050: } else {
1.285 albertel 6051: &init_perm();
1.104 albertel 6052: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 6053: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 6054: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 6055: &pickStudentPage($request);
1.103 albertel 6056: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 6057: &displayPage($request);
1.104 albertel 6058: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 6059: &updateGradeByPage($request);
1.104 albertel 6060: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 6061: &processGroup($request);
1.104 albertel 6062: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 6063: $request->print(&gradingmenu($request));
1.104 albertel 6064: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 6065: $request->print(&viewgrades($request));
1.104 albertel 6066: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 6067: $request->print(&processHandGrade($request));
1.106 albertel 6068: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 6069: $request->print(&editgrades($request));
1.106 albertel 6070: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 6071: $request->print(&verifyreceipt($request));
1.106 albertel 6072: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 6073: $request->print(&upcsvScores_form($request));
1.106 albertel 6074: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 6075: $request->print(&csvupload($request));
1.106 albertel 6076: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 6077: $request->print(&csvuploadmap($request));
1.246 albertel 6078: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 6079: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 6080: $request->print(&csvuploadoptions($request));
1.41 ng 6081: } else {
1.257 albertel 6082: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
6083: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 6084: } else {
1.257 albertel 6085: $env{'form.upfile_associate'} = 'forward';
1.41 ng 6086: }
6087: $request->print(&csvuploadmap($request));
6088: }
1.246 albertel 6089: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
6090: $request->print(&csvuploadassign($request));
1.106 albertel 6091: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 6092: $request->print(&scantron_selectphase($request));
1.203 albertel 6093: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
6094: $request->print(&scantron_do_warning($request));
1.142 albertel 6095: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
6096: $request->print(&scantron_validate_file($request));
1.106 albertel 6097: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 6098: $request->print(&scantron_process_students($request));
1.157 albertel 6099: } elsif ($command eq 'scantronupload' &&
1.257 albertel 6100: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6101: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 6102: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 6103: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 6104: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6105: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 6106: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 6107: } elsif ($command eq 'scantron_download' &&
1.257 albertel 6108: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 6109: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 6110: } elsif ($command) {
1.157 albertel 6111: $request->print("Access Denied ($command)");
1.26 albertel 6112: }
1.2 albertel 6113: }
1.353 albertel 6114: $request->print(&Apache::loncommon::end_page());
1.44 ng 6115: return '';
6116: }
6117:
1.1 albertel 6118: 1;
6119:
1.13 albertel 6120: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>