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